diff --git a/.travis.yml b/.travis.yml index 521b32447..8cc248c60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,4 +18,4 @@ env: - TYPESCRIPT=typescript@2.1.5 - TYPESCRIPT=typescript@2.2.1 - TYPESCRIPT=typescript@2.3.1 - - TYPESCRIPT=typescript@next +# - TYPESCRIPT=typescript@next diff --git a/appveyor.yml b/appveyor.yml index f1c94dd6e..6a6f9111a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,7 +8,7 @@ environment: - TYPESCRIPT: typescript@2.1.5 - TYPESCRIPT: typescript@2.2.1 - TYPESCRIPT: typescript@2.3.1 - - TYPESCRIPT: typescript@next +# - TYPESCRIPT: typescript@next install: - ps: Install-Product node $env:nodejs_version - npm install diff --git a/package.json b/package.json index 9ea0e4d53..9cb57ca28 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "mocha": "^3.1.0", "phantomjs-prebuilt": "^2.1.2", "rimraf": "^2.4.2", - "typescript": "^2.2.1", + "typescript": "^2.4.0", "typings": "^2.0.0", "webpack": "^2.2.0" } diff --git a/src/index.ts b/src/index.ts index 92fa4b913..00710079a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -84,6 +84,7 @@ function getLoaderOptions(loader: interfaces.Webpack) { visualStudioErrorFormat: false, compilerOptions: {}, appendTsSuffixTo: [], + transformers: {}, entryFileIsJs: false, happyPackMode: false, }, configFileOptions, queryOptions); @@ -185,6 +186,7 @@ function getTranspilationEmit( const { outputText, sourceMapText, diagnostics } = instance.compiler.transpileModule(contents, { compilerOptions: instance.compilerOptions, + transformers: instance.transformers, reportDiagnostics: true, fileName, }); diff --git a/src/instances.ts b/src/instances.ts index a7b4e296a..63aa3c414 100644 --- a/src/instances.ts +++ b/src/instances.ts @@ -58,6 +58,8 @@ export function getTypeScriptInstance( const compilerOptions = compilerSetup.getCompilerOptions(compilerCompatible, compiler, configParseResult); const files: interfaces.TSFiles = {}; + const getCustomTransformers = loaderOptions.getCustomTransformers || Function.prototype; + if (loaderOptions.transpileOnly) { // quick return for transpiling // we do need to check for any issues with TS options though @@ -70,8 +72,8 @@ export function getTypeScriptInstance( loader._module.errors, utils.formatErrors(diagnostics, loaderOptions, compiler, {file: configFilePath || 'tsconfig.json'})); } - - return { instance: instances[loaderOptions.instance] = { compiler, compilerOptions, loaderOptions, files, dependencyGraph: {}, reverseDependencyGraph: {} }}; + + return { instance: instances[loaderOptions.instance] = { compiler, compilerOptions, loaderOptions, files, dependencyGraph: {}, reverseDependencyGraph: {}, transformers: getCustomTransformers() }}; } // Load initial files (core lib files, any files specified in tsconfig.json) @@ -103,6 +105,7 @@ export function getTypeScriptInstance( files, languageService: null, version: 0, + transformers: getCustomTransformers(), dependencyGraph: {}, reverseDependencyGraph: {}, modifiedFiles: null, diff --git a/src/interfaces.ts b/src/interfaces.ts index c12be6006..4b4ec8758 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -217,6 +217,7 @@ export interface TSInstance { dependencyGraph: DependencyGraph; reverseDependencyGraph: ReverseDependencyGraph; filesWithErrors?: TSFiles; + transformers: typescript.CustomTransformers; } export interface LoaderOptionsCache { @@ -255,6 +256,7 @@ export interface LoaderOptions { appendTsSuffixTo: RegExp[]; entryFileIsJs: boolean; happyPackMode: boolean; + getCustomTransformers?(): typescript.CustomTransformers | undefined; } export interface TSFile { diff --git a/src/servicesHost.ts b/src/servicesHost.ts index 2571d625f..d59408d68 100644 --- a/src/servicesHost.ts +++ b/src/servicesHost.ts @@ -69,10 +69,11 @@ function makeServicesHost( getDefaultLibFileName: (options: typescript.CompilerOptions) => compiler.getDefaultLibFilePath(options), getNewLine: () => newLine, log: log.log, - resolveModuleNames: (moduleNames: string[], containingFile: string) => + resolveModuleNames: (moduleNames: string[], containingFile: string) => resolveModuleNames( resolveSync, moduleResolutionHost, appendTsSuffixTo, scriptRegex, instance, - moduleNames, containingFile) + moduleNames, containingFile), + getCustomTransformers: () => instance.transformers }; } @@ -85,7 +86,7 @@ function resolveModuleNames( moduleNames: string[], containingFile: string ) { - const resolvedModules = moduleNames.map(moduleName => + const resolvedModules = moduleNames.map(moduleName => resolveModuleName(resolveSync, moduleResolutionHost, appendTsSuffixTo, scriptRegex, instance, moduleName, containingFile) ); @@ -106,7 +107,7 @@ function resolveModuleName( containingFile: string ) { const { compiler, compilerOptions } = instance; - + let resolutionResult: interfaces.ResolvedModule; try { diff --git a/test/comparison-tests/customTransformer/app.ts b/test/comparison-tests/customTransformer/app.ts new file mode 100644 index 000000000..194c2d430 --- /dev/null +++ b/test/comparison-tests/customTransformer/app.ts @@ -0,0 +1,2 @@ +var message = "Hello from me!" +console.log(message); \ No newline at end of file diff --git a/test/comparison-tests/customTransformer/expectedOutput-2.3/bundle.js b/test/comparison-tests/customTransformer/expectedOutput-2.3/bundle.js new file mode 100644 index 000000000..6f4850711 --- /dev/null +++ b/test/comparison-tests/customTransformer/expectedOutput-2.3/bundle.js @@ -0,0 +1,78 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // identity function for calling harmony imports with the correct context +/******/ __webpack_require__.i = function(value) { return value; }; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports) { + +var message = "HELLO FROM ME!"; +console.log(message); + + +/***/ }) +/******/ ]); \ No newline at end of file diff --git a/test/comparison-tests/customTransformer/expectedOutput-2.3/bundle.transpiled.js b/test/comparison-tests/customTransformer/expectedOutput-2.3/bundle.transpiled.js new file mode 100644 index 000000000..ea93c308c --- /dev/null +++ b/test/comparison-tests/customTransformer/expectedOutput-2.3/bundle.transpiled.js @@ -0,0 +1,78 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // identity function for calling harmony imports with the correct context +/******/ __webpack_require__.i = function(value) { return value; }; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports) { + +var message = "Hello from me!"; +console.log(message); + + +/***/ }) +/******/ ]); \ No newline at end of file diff --git a/test/comparison-tests/customTransformer/expectedOutput-2.3/output.txt b/test/comparison-tests/customTransformer/expectedOutput-2.3/output.txt new file mode 100644 index 000000000..7196dfcf8 --- /dev/null +++ b/test/comparison-tests/customTransformer/expectedOutput-2.3/output.txt @@ -0,0 +1,4 @@ + Asset Size Chunks Chunk Names +bundle.js 2.69 kB 0 [emitted] main +chunk {0} bundle.js (main) 54 bytes [entry] [rendered] + [0] ./.test/customTransformer/app.ts 54 bytes {0} [built] \ No newline at end of file diff --git a/test/comparison-tests/customTransformer/expectedOutput-2.3/patch0/bundle.js b/test/comparison-tests/customTransformer/expectedOutput-2.3/patch0/bundle.js new file mode 100644 index 000000000..553a36e58 --- /dev/null +++ b/test/comparison-tests/customTransformer/expectedOutput-2.3/patch0/bundle.js @@ -0,0 +1,78 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // identity function for calling harmony imports with the correct context +/******/ __webpack_require__.i = function(value) { return value; }; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports) { + +var message = "HELLO FROM HIM!"; +console.log(message); + + +/***/ }) +/******/ ]); \ No newline at end of file diff --git a/test/comparison-tests/customTransformer/expectedOutput-2.3/patch0/bundle.transpiled.js b/test/comparison-tests/customTransformer/expectedOutput-2.3/patch0/bundle.transpiled.js new file mode 100644 index 000000000..18f1a663e --- /dev/null +++ b/test/comparison-tests/customTransformer/expectedOutput-2.3/patch0/bundle.transpiled.js @@ -0,0 +1,78 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // identity function for calling harmony imports with the correct context +/******/ __webpack_require__.i = function(value) { return value; }; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports) { + +var message = "Hello from him!"; +console.log(message); + + +/***/ }) +/******/ ]); \ No newline at end of file diff --git a/test/comparison-tests/customTransformer/expectedOutput-2.3/patch0/output.txt b/test/comparison-tests/customTransformer/expectedOutput-2.3/patch0/output.txt new file mode 100644 index 000000000..c17569629 --- /dev/null +++ b/test/comparison-tests/customTransformer/expectedOutput-2.3/patch0/output.txt @@ -0,0 +1,4 @@ + Asset Size Chunks Chunk Names +bundle.js 2.69 kB 0 [emitted] main +chunk {0} bundle.js (main) 55 bytes [entry] [rendered] + [0] ./.test/customTransformer/app.ts 55 bytes {0} [built] \ No newline at end of file diff --git a/test/comparison-tests/customTransformer/expectedOutput-2.3/patch1/bundle.js b/test/comparison-tests/customTransformer/expectedOutput-2.3/patch1/bundle.js new file mode 100644 index 000000000..de6e20451 --- /dev/null +++ b/test/comparison-tests/customTransformer/expectedOutput-2.3/patch1/bundle.js @@ -0,0 +1,78 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // identity function for calling harmony imports with the correct context +/******/ __webpack_require__.i = function(value) { return value; }; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports) { + +var message = "HELLO FROM US!"; +console.log(message); + + +/***/ }) +/******/ ]); \ No newline at end of file diff --git a/test/comparison-tests/customTransformer/expectedOutput-2.3/patch1/bundle.transpiled.js b/test/comparison-tests/customTransformer/expectedOutput-2.3/patch1/bundle.transpiled.js new file mode 100644 index 000000000..5c4afd468 --- /dev/null +++ b/test/comparison-tests/customTransformer/expectedOutput-2.3/patch1/bundle.transpiled.js @@ -0,0 +1,78 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // identity function for calling harmony imports with the correct context +/******/ __webpack_require__.i = function(value) { return value; }; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports) { + +var message = "Hello from us!"; +console.log(message); + + +/***/ }) +/******/ ]); \ No newline at end of file diff --git a/test/comparison-tests/customTransformer/expectedOutput-2.3/patch1/output.txt b/test/comparison-tests/customTransformer/expectedOutput-2.3/patch1/output.txt new file mode 100644 index 000000000..7196dfcf8 --- /dev/null +++ b/test/comparison-tests/customTransformer/expectedOutput-2.3/patch1/output.txt @@ -0,0 +1,4 @@ + Asset Size Chunks Chunk Names +bundle.js 2.69 kB 0 [emitted] main +chunk {0} bundle.js (main) 54 bytes [entry] [rendered] + [0] ./.test/customTransformer/app.ts 54 bytes {0} [built] \ No newline at end of file diff --git a/test/comparison-tests/customTransformer/patch0/app.ts b/test/comparison-tests/customTransformer/patch0/app.ts new file mode 100644 index 000000000..e9c84a17f --- /dev/null +++ b/test/comparison-tests/customTransformer/patch0/app.ts @@ -0,0 +1,2 @@ +var message = "Hello from him!" +console.log(message); \ No newline at end of file diff --git a/test/comparison-tests/customTransformer/patch1/app.ts b/test/comparison-tests/customTransformer/patch1/app.ts new file mode 100644 index 000000000..13be02a06 --- /dev/null +++ b/test/comparison-tests/customTransformer/patch1/app.ts @@ -0,0 +1,2 @@ +var message = "Hello from us!" +console.log(message); \ No newline at end of file diff --git a/test/comparison-tests/customTransformer/tsconfig.json b/test/comparison-tests/customTransformer/tsconfig.json new file mode 100644 index 000000000..94d996e96 --- /dev/null +++ b/test/comparison-tests/customTransformer/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + + } +} \ No newline at end of file diff --git a/test/comparison-tests/customTransformer/uppercaseStringLiteralTransformer.js b/test/comparison-tests/customTransformer/uppercaseStringLiteralTransformer.js new file mode 100644 index 000000000..3c72c182c --- /dev/null +++ b/test/comparison-tests/customTransformer/uppercaseStringLiteralTransformer.js @@ -0,0 +1,16 @@ +"use strict"; +exports.__esModule = true; +var ts = require("typescript"); +var transformer = function (context) { + var visitor = function (node) { + if (node.kind === ts.SyntaxKind.StringLiteral) { + var text = node.text; + if (text !== text.toUpperCase()) { + return ts.createLiteral(text.toUpperCase()); + } + } + return ts.visitEachChild(node, visitor, context); + }; + return function (node) { return ts.visitNode(node, visitor); }; +}; +exports["default"] = transformer; diff --git a/test/comparison-tests/customTransformer/webpack.config.js b/test/comparison-tests/customTransformer/webpack.config.js new file mode 100644 index 000000000..986ef576c --- /dev/null +++ b/test/comparison-tests/customTransformer/webpack.config.js @@ -0,0 +1,28 @@ +var path = require('path') + +var uppercaseStringLiteralTransformer = require('./uppercaseStringLiteralTransformer').default; + +module.exports = { + entry: './app.ts', + output: { + filename: 'bundle.js' + }, + resolve: { + extensions: ['.ts', '.js'] + }, + module: { + rules: [ + { + test: /\.ts$/, + loader: 'ts-loader', + options: { + getCustomTransformers: () => ({ // note parens + before: [uppercaseStringLiteralTransformer] + }) + } + } + ] + } +} + + diff --git a/test/custom-transformers/tsconfig.json b/test/custom-transformers/tsconfig.json new file mode 100644 index 000000000..94d996e96 --- /dev/null +++ b/test/custom-transformers/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + + } +} \ No newline at end of file