Skip to content

Commit

Permalink
Add support for specifying target: es6 and module: commonjs at the sa…
Browse files Browse the repository at this point in the history
…me time.

Additionally, simplify logic for loading the default lib.
  • Loading branch information
jbrantly committed Jan 13, 2016
1 parent 7b4e18f commit dc48cab
Show file tree
Hide file tree
Showing 21 changed files with 229 additions and 68 deletions.
14 changes: 3 additions & 11 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,10 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
instance.compilerOptions = objectAssign<typescript.CompilerOptions>(compilerOptions, configParseResult.options);
filesToLoad = configParseResult.fileNames;

var libFileName = 'lib.d.ts';

// Special handling for ES6 targets
if (compilerOptions.target == 2 /* ES6 */) {
// special handling for TS 1.6 and target: es6
if (compilerCompatible && semver.lt(compiler.version, '1.7.3-0') && compilerOptions.target == 2 /* ES6 */) {
compilerOptions.module = 0 /* None */;
libFileName = 'lib.es6.d.ts';
}
libFileName = path.join(path.dirname(require.resolve(loaderOptions.compiler)), libFileName);

if (loaderOptions.transpileOnly) {
// quick return for transpiling
Expand All @@ -297,10 +293,6 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
return { instance: instances[loaderOptions.instance] = { compiler, compilerOptions, loaderOptions, files }};
}

if (!compilerOptions.noLib) {
filesToLoad.push(libFileName);
}

// Load initial files (core lib files, any files specified in tsconfig.json)
filesToLoad.forEach(filePath => {
filePath = path.normalize(filePath);
Expand Down Expand Up @@ -356,7 +348,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
},
getCurrentDirectory: () => process.cwd(),
getCompilationSettings: () => compilerOptions,
getDefaultLibFileName: options => libFileName,
getDefaultLibFileName: options => compiler.getDefaultLibFilePath(options),
getNewLine: () => newLine,
log: log,
resolveModuleNames: (moduleNames: string[], containingFile: string) => {
Expand Down
53 changes: 53 additions & 0 deletions test/es6/expectedOutput-1.8/bundle.transpiled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/******/ (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] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = 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;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports) {

"use strict";
({ get x() { return 1; } });
Symbol;


/***/ }
/******/ ]);
4 changes: 4 additions & 0 deletions test/es6/expectedOutput-1.8/output.transpiled.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Asset Size Chunks Chunk Names
bundle.js 1.44 kB 0 [emitted] main
chunk {0} bundle.js (main) 51 bytes [rendered]
[0] ./.test/es6/app.ts 51 bytes {0} [built]
4 changes: 0 additions & 4 deletions test/es6resolveParent/expectedOutput-1.7/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@

"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var BaseComponent = function BaseComponent() {
Expand Down
6 changes: 3 additions & 3 deletions test/es6resolveParent/expectedOutput-1.7/output.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Asset Size Chunks Chunk Names
bundle.js 1.76 kB 0 [emitted] main
chunk {0} bundle.js (main) 365 bytes [rendered]
[0] ./.test/es6resolveParent/index.tsx 365 bytes {0} [built]
bundle.js 1.69 kB 0 [emitted] main
chunk {0} bundle.js (main) 299 bytes [rendered]
[0] ./.test/es6resolveParent/index.tsx 299 bytes {0} [built]
4 changes: 0 additions & 4 deletions test/es6resolveParent/expectedOutput-1.8/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@

"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var BaseComponent = function BaseComponent() {
Expand Down
6 changes: 3 additions & 3 deletions test/es6resolveParent/expectedOutput-1.8/output.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Asset Size Chunks Chunk Names
bundle.js 1.76 kB 0 [emitted] main
chunk {0} bundle.js (main) 365 bytes [rendered]
[0] ./.test/es6resolveParent/index.tsx 365 bytes {0} [built]
bundle.js 1.69 kB 0 [emitted] main
chunk {0} bundle.js (main) 299 bytes [rendered]
[0] ./.test/es6resolveParent/index.tsx 299 bytes {0} [built]
1 change: 1 addition & 0 deletions test/es6withCJS/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'a';
6 changes: 6 additions & 0 deletions test/es6withCJS/expectedOutput-1.6/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

ERROR in ./.test/es6withCJS/app.ts
Module parse failed: index.js!app.ts Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| export default 'a';
|
51 changes: 51 additions & 0 deletions test/es6withCJS/expectedOutput-1.7/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/******/ (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] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = 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;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports) {

exports.default = 'a';


/***/ }
/******/ ]);
4 changes: 4 additions & 0 deletions test/es6withCJS/expectedOutput-1.7/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Asset Size Chunks Chunk Names
bundle.js 1.41 kB 0 [emitted] main
chunk {0} bundle.js (main) 23 bytes [rendered]
[0] ./.test/es6withCJS/app.ts 23 bytes {0} [built]
53 changes: 53 additions & 0 deletions test/es6withCJS/expectedOutput-1.8/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/******/ (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] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = 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;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = 'a';


/***/ }
/******/ ]);
4 changes: 4 additions & 0 deletions test/es6withCJS/expectedOutput-1.8/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Asset Size Chunks Chunk Names
bundle.js 1.49 kB 0 [emitted] main
chunk {0} bundle.js (main) 100 bytes [rendered]
[0] ./.test/es6withCJS/app.ts 100 bytes {0} [built]
6 changes: 6 additions & 0 deletions test/es6withCJS/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs"
}
}
17 changes: 17 additions & 0 deletions test/es6withCJS/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
entry: './app.ts',
output: {
filename: 'bundle.js'
},
resolve: {
extensions: ['', '.ts', '.js']
},
module: {
loaders: [
{ test: /\.ts$/, loader: 'ts-loader' }
]
}
}

// for test harness purposes only, you would not need this in a normal project
module.exports.resolveLoader = { alias: { 'ts-loader': require('path').join(__dirname, "../../index.js") } }
1 change: 1 addition & 0 deletions test/issue81/expectedOutput-1.8/bundle.js.transpiled.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/issue81/expectedOutput-1.8/output.transpiled.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Asset Size Chunks Chunk Names
bundle.js 2.42 kB 0 [emitted] main
bundle.js.map 2.52 kB 0 [emitted] main
chunk {0} bundle.js, bundle.js.map (main) 896 bytes [rendered]
[0] ./.test/issue81/a.ts 896 bytes {0} [built]
18 changes: 2 additions & 16 deletions test/issue92/expectedOutput-1.7/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,16 @@

'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _submoduleSubmodule = __webpack_require__(1);

var _submoduleSubmodule2 = _interopRequireDefault(_submoduleSubmodule);

exports['default'] = _submoduleSubmodule2['default'];
module.exports = exports['default'];
var submodule_1 = __webpack_require__(1);
exports['default'] = submodule_1['default'];

/***/ },
/* 1 */
/***/ function(module, exports) {

"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = "Hello from submodule";
module.exports = exports["default"];

/***/ }
/******/ ]);
8 changes: 4 additions & 4 deletions test/issue92/expectedOutput-1.7/output.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Asset Size Chunks Chunk Names
bundle.js 2.03 kB 0 [emitted] main
chunk {0} bundle.js (main) 565 bytes [rendered]
[0] ./.test/issue92/app.ts 404 bytes {0} [built]
[1] ./.test/issue92/submodule/submodule.tsx 161 bytes {0} [built]
bundle.js 1.63 kB 0 [emitted] main
chunk {0} bundle.js (main) 170 bytes [rendered]
[0] ./.test/issue92/app.ts 111 bytes {0} [built]
[1] ./.test/issue92/submodule/submodule.tsx 59 bytes {0} [built]
24 changes: 5 additions & 19 deletions test/issue92/expectedOutput-1.8/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,18 @@
/* 0 */
/***/ function(module, exports, __webpack_require__) {

'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _submoduleSubmodule = __webpack_require__(1);

var _submoduleSubmodule2 = _interopRequireDefault(_submoduleSubmodule);

exports['default'] = _submoduleSubmodule2['default'];
module.exports = exports['default'];
"use strict";
var submodule_1 = __webpack_require__(1);
Object.defineProperty(exports, "__esModule", { value: true });
exports["default"] = submodule_1["default"];

/***/ },
/* 1 */
/***/ function(module, exports) {

"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "__esModule", { value: true });
exports["default"] = "Hello from submodule";
module.exports = exports["default"];

/***/ }
/******/ ]);
Loading

0 comments on commit dc48cab

Please sign in to comment.