From 4cf4a000cc9a3e792646ab5d77ac1014f64990f8 Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Fri, 12 Mar 2021 18:28:04 +0100 Subject: [PATCH 1/4] Fixes #1260 by generating declaration files for js files if allowJs is set to true. --- src/after-compile.ts | 10 +- .../declarationOutputAllowJs/app.ts | 9 ++ .../expectedOutput-4.1/.output/app.d.ts | 5 + .../expectedOutput-4.1/.output/sub/dep.d.ts | 6 + .../expectedOutput-4.1/bundle.js | 113 ++++++++++++++++++ .../expectedOutput-4.1/output.txt | 12 ++ .../expectedOutput-transpile-4.1/bundle.js | 113 ++++++++++++++++++ .../expectedOutput-transpile-4.1/output.txt | 5 + .../declarationOutputAllowJs/sub/dep.js | 9 ++ .../declarationOutputAllowJs/tsconfig.json | 11 ++ .../webpack.config.js | 15 +++ 11 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 test/comparison-tests/declarationOutputAllowJs/app.ts create mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/app.d.ts create mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/sub/dep.d.ts create mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/bundle.js create mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/output.txt create mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/bundle.js create mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/output.txt create mode 100644 test/comparison-tests/declarationOutputAllowJs/sub/dep.js create mode 100644 test/comparison-tests/declarationOutputAllowJs/tsconfig.json create mode 100644 test/comparison-tests/declarationOutputAllowJs/webpack.config.js diff --git a/src/after-compile.ts b/src/after-compile.ts index 99cb9f37b..0ef7bf857 100644 --- a/src/after-compile.ts +++ b/src/after-compile.ts @@ -355,15 +355,21 @@ function provideSolutionErrorsToWebpack( } /** - * gather all declaration files from TypeScript and output them to webpack + * gather all declaration files from TypeScript and output them to webpack. + * JavaScript declaration files are included if `allowJs` is set. */ function provideDeclarationFilesToWebpack( filesToCheckForErrors: TSFiles, instance: TSInstance, compilation: webpack.Compilation ) { + const filePathRegex = + instance.compilerOptions.allowJs === true + ? constants.dtsTsTsxJsJsxRegex + : constants.dtsTsTsxRegex; + for (const { fileName } of filesToCheckForErrors.values()) { - if (fileName.match(constants.tsTsxRegex) === null) { + if (fileName.match(filePathRegex) === null) { continue; } diff --git a/test/comparison-tests/declarationOutputAllowJs/app.ts b/test/comparison-tests/declarationOutputAllowJs/app.ts new file mode 100644 index 000000000..77428dd19 --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/app.ts @@ -0,0 +1,9 @@ +import dep = require('./sub/dep'); + +class Test extends dep { + doSomething() { + + } +} + +export = Test; \ No newline at end of file diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/app.d.ts b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/app.d.ts new file mode 100644 index 000000000..42c1b770a --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/app.d.ts @@ -0,0 +1,5 @@ +import dep = require('./sub/dep'); +declare class Test extends dep { + doSomething(): void; +} +export = Test; diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/sub/dep.d.ts b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/sub/dep.d.ts new file mode 100644 index 000000000..41cbbcc68 --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/sub/dep.d.ts @@ -0,0 +1,6 @@ +export class Test { + /** + * @param {number} x + */ + doSomething(x: number): number; +} diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/bundle.js b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/bundle.js new file mode 100644 index 000000000..6874bab79 --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/bundle.js @@ -0,0 +1,113 @@ +/******/ (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; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // 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 = "./app.ts"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./app.ts": +/*!****************!*\ + !*** ./app.ts ***! + \****************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +eval("\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar dep = __webpack_require__(/*! ./sub/dep */ \"./sub/dep.js\");\nvar Test = /** @class */ (function (_super) {\n __extends(Test, _super);\n function Test() {\n return _super !== null && _super.apply(this, arguments) || this;\n }\n Test.prototype.doSomething = function () {\n };\n return Test;\n}(dep));\nmodule.exports = Test;\n\n\n//# sourceURL=webpack:///./app.ts?"); + +/***/ }), + +/***/ "./sub/dep.js": +/*!********************!*\ + !*** ./sub/dep.js ***! + \********************/ +/*! exports provided: Test */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Test\", function() { return Test; });\n\nclass Test {\n\t/**\n\t * @param {number} x \n\t */\n\tdoSomething(x) {\n\t\treturn x;\n\t}\n}\n\n\n//# sourceURL=webpack:///./sub/dep.js?"); + +/***/ }) + +/******/ }); \ No newline at end of file diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/output.txt b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/output.txt new file mode 100644 index 000000000..234f21f1a --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/output.txt @@ -0,0 +1,12 @@ + Asset Size Chunks Chunk Names + .output/app.d.ts 110 bytes [emitted] +.output/sub/dep.d.ts 99 bytes [emitted] + bundle.js 5.25 KiB main [emitted] main +Entrypoint main = bundle.js +[./app.ts] 934 bytes {main} [built] [1 error] +[./sub/dep.js] 89 bytes {main} [built] + +ERROR in app.ts +./app.ts 3:19-22 +[tsl] ERROR in app.ts(3,20) + TS2507: Type 'typeof import("/declarationOutputAllowJs/sub/dep")' is not a constructor function type. \ No newline at end of file diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/bundle.js b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/bundle.js new file mode 100644 index 000000000..6874bab79 --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/bundle.js @@ -0,0 +1,113 @@ +/******/ (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; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // 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 = "./app.ts"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./app.ts": +/*!****************!*\ + !*** ./app.ts ***! + \****************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +eval("\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar dep = __webpack_require__(/*! ./sub/dep */ \"./sub/dep.js\");\nvar Test = /** @class */ (function (_super) {\n __extends(Test, _super);\n function Test() {\n return _super !== null && _super.apply(this, arguments) || this;\n }\n Test.prototype.doSomething = function () {\n };\n return Test;\n}(dep));\nmodule.exports = Test;\n\n\n//# sourceURL=webpack:///./app.ts?"); + +/***/ }), + +/***/ "./sub/dep.js": +/*!********************!*\ + !*** ./sub/dep.js ***! + \********************/ +/*! exports provided: Test */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Test\", function() { return Test; });\n\nclass Test {\n\t/**\n\t * @param {number} x \n\t */\n\tdoSomething(x) {\n\t\treturn x;\n\t}\n}\n\n\n//# sourceURL=webpack:///./sub/dep.js?"); + +/***/ }) + +/******/ }); \ No newline at end of file diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/output.txt b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/output.txt new file mode 100644 index 000000000..456e7ade1 --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/output.txt @@ -0,0 +1,5 @@ + Asset Size Chunks Chunk Names +bundle.js 5.25 KiB main [emitted] main +Entrypoint main = bundle.js +[./app.ts] 934 bytes {main} [built] +[./sub/dep.js] 89 bytes {main} [built] \ No newline at end of file diff --git a/test/comparison-tests/declarationOutputAllowJs/sub/dep.js b/test/comparison-tests/declarationOutputAllowJs/sub/dep.js new file mode 100644 index 000000000..2c8a0dde7 --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/sub/dep.js @@ -0,0 +1,9 @@ + +export class Test { + /** + * @param {number} x + */ + doSomething(x) { + return x; + } +} diff --git a/test/comparison-tests/declarationOutputAllowJs/tsconfig.json b/test/comparison-tests/declarationOutputAllowJs/tsconfig.json new file mode 100644 index 000000000..a777685f1 --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "declaration": true, + "declarationDir": ".output", + "allowJs": true + }, + "files": [ + "./app.ts", + "./sub/dep.js" + ] +} diff --git a/test/comparison-tests/declarationOutputAllowJs/webpack.config.js b/test/comparison-tests/declarationOutputAllowJs/webpack.config.js new file mode 100644 index 000000000..2159baf3b --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/webpack.config.js @@ -0,0 +1,15 @@ +module.exports = { + mode: 'development', + entry: './app.ts', + output: { + filename: 'bundle.js' + }, + resolve: { + extensions: ['.ts', '.js'] + }, + module: { + rules: [ + { test: /\.ts$/, loader: 'ts-loader' } + ] + } +} From dca8aac0a2988a4cc7e80354673c344af101da8b Mon Sep 17 00:00:00 2001 From: Matthias Villiger Date: Wed, 22 Jun 2022 11:21:02 +0200 Subject: [PATCH 2/4] Fix declarationOutputAllowJs test Update expected test output for 4.7 and stabilize expectation to be OS independent. --- .../declarationOutputAllowJs/app.ts | 6 +- .../expectedOutput-4.1/.output/app.d.ts | 5 - .../expectedOutput-4.1/bundle.js | 113 ------------------ .../expectedOutput-4.1/output.txt | 12 -- .../expectedOutput-4.7/.output/app.d.ts | 4 + .../.output/sub/dep.d.ts | 0 .../expectedOutput-4.7/bundle.js | 57 +++++++++ .../expectedOutput-4.7/output.txt | 12 ++ .../expectedOutput-transpile-4.1/bundle.js | 113 ------------------ .../expectedOutput-transpile-4.1/output.txt | 5 - .../expectedOutput-transpile-4.7/bundle.js | 57 +++++++++ .../expectedOutput-transpile-4.7/output.txt | 3 + 12 files changed, 135 insertions(+), 252 deletions(-) delete mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/app.d.ts delete mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/bundle.js delete mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/output.txt create mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/.output/app.d.ts rename test/comparison-tests/declarationOutputAllowJs/{expectedOutput-4.1 => expectedOutput-4.7}/.output/sub/dep.d.ts (100%) create mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/bundle.js create mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/output.txt delete mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/bundle.js delete mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/output.txt create mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.7/bundle.js create mode 100644 test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.7/output.txt diff --git a/test/comparison-tests/declarationOutputAllowJs/app.ts b/test/comparison-tests/declarationOutputAllowJs/app.ts index 77428dd19..22900d22e 100644 --- a/test/comparison-tests/declarationOutputAllowJs/app.ts +++ b/test/comparison-tests/declarationOutputAllowJs/app.ts @@ -1,9 +1,7 @@ import dep = require('./sub/dep'); -class Test extends dep { - doSomething() { - - } +class Test { + private _field?: dep; } export = Test; \ No newline at end of file diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/app.d.ts b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/app.d.ts deleted file mode 100644 index 42c1b770a..000000000 --- a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/app.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import dep = require('./sub/dep'); -declare class Test extends dep { - doSomething(): void; -} -export = Test; diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/bundle.js b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/bundle.js deleted file mode 100644 index 6874bab79..000000000 --- a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/bundle.js +++ /dev/null @@ -1,113 +0,0 @@ -/******/ (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; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); -/******/ } -/******/ }; -/******/ -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ -/******/ // create a fake namespace object -/******/ // mode & 1: value is a module id, require it -/******/ // mode & 2: merge all properties of value into the ns -/******/ // mode & 4: return value when already ns object -/******/ // mode & 8|1: behave like require -/******/ __webpack_require__.t = function(value, mode) { -/******/ if(mode & 1) value = __webpack_require__(value); -/******/ if(mode & 8) return value; -/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; -/******/ var ns = Object.create(null); -/******/ __webpack_require__.r(ns); -/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); -/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); -/******/ return ns; -/******/ }; -/******/ -/******/ // 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 = "./app.ts"); -/******/ }) -/************************************************************************/ -/******/ ({ - -/***/ "./app.ts": -/*!****************!*\ - !*** ./app.ts ***! - \****************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar dep = __webpack_require__(/*! ./sub/dep */ \"./sub/dep.js\");\nvar Test = /** @class */ (function (_super) {\n __extends(Test, _super);\n function Test() {\n return _super !== null && _super.apply(this, arguments) || this;\n }\n Test.prototype.doSomething = function () {\n };\n return Test;\n}(dep));\nmodule.exports = Test;\n\n\n//# sourceURL=webpack:///./app.ts?"); - -/***/ }), - -/***/ "./sub/dep.js": -/*!********************!*\ - !*** ./sub/dep.js ***! - \********************/ -/*! exports provided: Test */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Test\", function() { return Test; });\n\nclass Test {\n\t/**\n\t * @param {number} x \n\t */\n\tdoSomething(x) {\n\t\treturn x;\n\t}\n}\n\n\n//# sourceURL=webpack:///./sub/dep.js?"); - -/***/ }) - -/******/ }); \ No newline at end of file diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/output.txt b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/output.txt deleted file mode 100644 index 234f21f1a..000000000 --- a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/output.txt +++ /dev/null @@ -1,12 +0,0 @@ - Asset Size Chunks Chunk Names - .output/app.d.ts 110 bytes [emitted] -.output/sub/dep.d.ts 99 bytes [emitted] - bundle.js 5.25 KiB main [emitted] main -Entrypoint main = bundle.js -[./app.ts] 934 bytes {main} [built] [1 error] -[./sub/dep.js] 89 bytes {main} [built] - -ERROR in app.ts -./app.ts 3:19-22 -[tsl] ERROR in app.ts(3,20) - TS2507: Type 'typeof import("/declarationOutputAllowJs/sub/dep")' is not a constructor function type. \ No newline at end of file diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/.output/app.d.ts b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/.output/app.d.ts new file mode 100644 index 000000000..cb14f0604 --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/.output/app.d.ts @@ -0,0 +1,4 @@ +declare class Test { + private _field?; +} +export = Test; diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/sub/dep.d.ts b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/.output/sub/dep.d.ts similarity index 100% rename from test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.1/.output/sub/dep.d.ts rename to test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/.output/sub/dep.d.ts diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/bundle.js b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/bundle.js new file mode 100644 index 000000000..73b79e496 --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/bundle.js @@ -0,0 +1,57 @@ +/* + * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). + * This devtool is neither made for production nor for readable output files. + * It uses "eval()" calls to create a separate source file in the browser devtools. + * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) + * or disable the default devtool with "devtool: false". + * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). + */ +/******/ (() => { // webpackBootstrap +/******/ "use strict"; +/******/ var __webpack_modules__ = ({ + +/***/ "./app.ts": +/*!****************!*\ + !*** ./app.ts ***! + \****************/ +/***/ ((module) => { + +eval("\nvar Test = /** @class */ (function () {\n function Test() {\n }\n return Test;\n}());\nmodule.exports = Test;\n\n\n//# sourceURL=webpack:///./app.ts?"); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ // Check if module is in cache +/******/ var cachedModule = __webpack_module_cache__[moduleId]; +/******/ if (cachedModule !== undefined) { +/******/ return cachedModule.exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/************************************************************************/ +/******/ +/******/ // startup +/******/ // Load entry module and return exports +/******/ // This entry module is referenced by other modules so it can't be inlined +/******/ var __webpack_exports__ = __webpack_require__("./app.ts"); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/output.txt b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/output.txt new file mode 100644 index 000000000..98b03714d --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-4.7/output.txt @@ -0,0 +1,12 @@ +asset bundle.js 2.19 KiB [emitted] (name: main) +asset .output/sub/dep.d.ts 99 bytes [emitted] +asset .output/app.d.ts 59 bytes [emitted] +./app.ts 128 bytes [built] [code generated] [1 error] + +ERROR in app.ts +./app.ts 4:18-21 +[tsl] ERROR in app.ts(4,19) + TS2709: Cannot use namespace 'dep' as a type. +ts-loader-default_609318b4f68865d3 + +webpack compiled with 1 error \ No newline at end of file diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/bundle.js b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/bundle.js deleted file mode 100644 index 6874bab79..000000000 --- a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/bundle.js +++ /dev/null @@ -1,113 +0,0 @@ -/******/ (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; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); -/******/ } -/******/ }; -/******/ -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ -/******/ // create a fake namespace object -/******/ // mode & 1: value is a module id, require it -/******/ // mode & 2: merge all properties of value into the ns -/******/ // mode & 4: return value when already ns object -/******/ // mode & 8|1: behave like require -/******/ __webpack_require__.t = function(value, mode) { -/******/ if(mode & 1) value = __webpack_require__(value); -/******/ if(mode & 8) return value; -/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; -/******/ var ns = Object.create(null); -/******/ __webpack_require__.r(ns); -/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); -/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); -/******/ return ns; -/******/ }; -/******/ -/******/ // 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 = "./app.ts"); -/******/ }) -/************************************************************************/ -/******/ ({ - -/***/ "./app.ts": -/*!****************!*\ - !*** ./app.ts ***! - \****************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar dep = __webpack_require__(/*! ./sub/dep */ \"./sub/dep.js\");\nvar Test = /** @class */ (function (_super) {\n __extends(Test, _super);\n function Test() {\n return _super !== null && _super.apply(this, arguments) || this;\n }\n Test.prototype.doSomething = function () {\n };\n return Test;\n}(dep));\nmodule.exports = Test;\n\n\n//# sourceURL=webpack:///./app.ts?"); - -/***/ }), - -/***/ "./sub/dep.js": -/*!********************!*\ - !*** ./sub/dep.js ***! - \********************/ -/*! exports provided: Test */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Test\", function() { return Test; });\n\nclass Test {\n\t/**\n\t * @param {number} x \n\t */\n\tdoSomething(x) {\n\t\treturn x;\n\t}\n}\n\n\n//# sourceURL=webpack:///./sub/dep.js?"); - -/***/ }) - -/******/ }); \ No newline at end of file diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/output.txt b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/output.txt deleted file mode 100644 index 456e7ade1..000000000 --- a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.1/output.txt +++ /dev/null @@ -1,5 +0,0 @@ - Asset Size Chunks Chunk Names -bundle.js 5.25 KiB main [emitted] main -Entrypoint main = bundle.js -[./app.ts] 934 bytes {main} [built] -[./sub/dep.js] 89 bytes {main} [built] \ No newline at end of file diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.7/bundle.js b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.7/bundle.js new file mode 100644 index 000000000..73b79e496 --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.7/bundle.js @@ -0,0 +1,57 @@ +/* + * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). + * This devtool is neither made for production nor for readable output files. + * It uses "eval()" calls to create a separate source file in the browser devtools. + * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) + * or disable the default devtool with "devtool: false". + * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). + */ +/******/ (() => { // webpackBootstrap +/******/ "use strict"; +/******/ var __webpack_modules__ = ({ + +/***/ "./app.ts": +/*!****************!*\ + !*** ./app.ts ***! + \****************/ +/***/ ((module) => { + +eval("\nvar Test = /** @class */ (function () {\n function Test() {\n }\n return Test;\n}());\nmodule.exports = Test;\n\n\n//# sourceURL=webpack:///./app.ts?"); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ // Check if module is in cache +/******/ var cachedModule = __webpack_module_cache__[moduleId]; +/******/ if (cachedModule !== undefined) { +/******/ return cachedModule.exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/************************************************************************/ +/******/ +/******/ // startup +/******/ // Load entry module and return exports +/******/ // This entry module is referenced by other modules so it can't be inlined +/******/ var __webpack_exports__ = __webpack_require__("./app.ts"); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.7/output.txt b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.7/output.txt new file mode 100644 index 000000000..069369bc6 --- /dev/null +++ b/test/comparison-tests/declarationOutputAllowJs/expectedOutput-transpile-4.7/output.txt @@ -0,0 +1,3 @@ +asset bundle.js 2.19 KiB [emitted] (name: main) +./app.ts 128 bytes [built] [code generated] +webpack compiled successfully \ No newline at end of file From 5735645ba936102fb886fbb9aceb872dd91d40f1 Mon Sep 17 00:00:00 2001 From: Matthias Villiger Date: Wed, 22 Jun 2022 15:16:05 +0200 Subject: [PATCH 3/4] Update package.json and CHANGELOG.md for 9.3.1 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c85b8c3da..74dc30ca0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v9.3.1 + +* [Bug fix: Generate declaration files for js files if allowJs is set to true](https://github.com/TypeStrong/ts-loader/pull/1483) [#1260] - thanks @hediet + ## v9.3.0 * [simplify configuration for fork-ts-checker-webpack-plugin](https://github.com/TypeStrong/ts-loader/pull/1451) - thanks @piotr-oles diff --git a/package.json b/package.json index 5c608b308..16f9dd01e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-loader", - "version": "9.3.0", + "version": "9.3.1", "description": "TypeScript loader for webpack", "main": "index.js", "types": "dist", From a5e9bbd3ae55c9da00f8fbe67443ef1da51fdbc5 Mon Sep 17 00:00:00 2001 From: Matthias Villiger Date: Wed, 22 Jun 2022 15:40:15 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md Co-authored-by: John Reilly --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74dc30ca0..b4245f8b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## v9.3.1 -* [Bug fix: Generate declaration files for js files if allowJs is set to true](https://github.com/TypeStrong/ts-loader/pull/1483) [#1260] - thanks @hediet +* [Bug fix: Generate declaration files for js files if allowJs is set to true](https://github.com/TypeStrong/ts-loader/pull/1483) [#1260] - thanks @hediet and @mvilliger ## v9.3.0