Skip to content

Commit

Permalink
Add basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 10, 2020
1 parent ec04aa2 commit ce73ae8
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Module.ts
Expand Up @@ -562,7 +562,6 @@ export default class Module {
}
if (typeof inlineDynamicImport === 'boolean') {
this.inlineDynamicImport = inlineDynamicImport;
console.log(this.id, inlineDynamicImport);
}

timeStart('generate ast', 3);
Expand Down Expand Up @@ -642,6 +641,7 @@ export default class Module {
customTransformCache: this.customTransformCache,
dependencies: this.dependencies.map(module => module.id),
id: this.id,
inlineDynamicImport: this.inlineDynamicImport,
moduleSideEffects: this.moduleSideEffects,
originalCode: this.originalCode,
originalSourcemap: this.originalSourcemap,
Expand Down
3 changes: 3 additions & 0 deletions src/ModuleLoader.ts
Expand Up @@ -322,6 +322,9 @@ export class ModuleLoader {
if (typeof sourceDescription.moduleSideEffects === 'boolean') {
module.moduleSideEffects = sourceDescription.moduleSideEffects;
}
if (typeof sourceDescription.inlineDynamicImport === 'boolean') {
module.inlineDynamicImport = sourceDescription.inlineDynamicImport;
}
return transform(this.graph, sourceDescription, module);
})
.then((source: TransformModuleJSON | ModuleJSON) => {
Expand Down
@@ -0,0 +1,36 @@
const fs = require('fs');
const path = require('path');

module.exports = {
description: 'inlines dynamic imports marked for inlining',
options: {
input: 'main.js',
plugins: {
resolveId(id, importer) {
if (id.endsWith('dep-inlined-via-resolveId.js')) {
return this.resolve(id, importer, { skipSelf: true }).then(resolution =>
Object.assign({}, resolution, { inlineDynamicImport: true })
);
}
},
load(id) {
if (id.endsWith('dep-inlined-via-load.js')) {
return {
code: fs.readFileSync(path.resolve(__dirname, 'dep-inlined-via-load.js'), {
encoding: 'utf8'
}),
inlineDynamicImport: true
};
}
},
transform(code, id) {
if (id.endsWith('dep-inlined-via-transform.js')) {
return {
code,
inlineDynamicImport: true
};
}
}
}
}
};
@@ -0,0 +1,8 @@
define(['exports'], function (exports) { 'use strict';

console.log('not inlined');
const value = 'not inlined';

exports.value = value;

});
@@ -0,0 +1,34 @@
define(['require'], function (require) { 'use strict';

Promise.resolve().then(function () { return depInlinedViaResolveId; }).then(console.log);
Promise.resolve().then(function () { return depInlinedViaLoad; }).then(console.log);
Promise.resolve().then(function () { return depInlinedViaTransform; }).then(console.log);
new Promise(function (resolve, reject) { require(['./generated-dep-not-inlined'], resolve, reject) }).then(console.log);

console.log('main');

console.log('resolveId');
const value = 'resolveId';

var depInlinedViaResolveId = /*#__PURE__*/Object.freeze({
__proto__: null,
value: value
});

console.log('load');
const value$1 = 'load';

var depInlinedViaLoad = /*#__PURE__*/Object.freeze({
__proto__: null,
value: value$1
});

console.log('transform');
const value$2 = 'transform';

var depInlinedViaTransform = /*#__PURE__*/Object.freeze({
__proto__: null,
value: value$2
});

});
@@ -0,0 +1,6 @@
'use strict';

console.log('not inlined');
const value = 'not inlined';

exports.value = value;
@@ -0,0 +1,32 @@
'use strict';

Promise.resolve().then(function () { return depInlinedViaResolveId; }).then(console.log);
Promise.resolve().then(function () { return depInlinedViaLoad; }).then(console.log);
Promise.resolve().then(function () { return depInlinedViaTransform; }).then(console.log);
new Promise(function (resolve) { resolve(require('./generated-dep-not-inlined.js')); }).then(console.log);

console.log('main');

console.log('resolveId');
const value = 'resolveId';

var depInlinedViaResolveId = /*#__PURE__*/Object.freeze({
__proto__: null,
value: value
});

console.log('load');
const value$1 = 'load';

var depInlinedViaLoad = /*#__PURE__*/Object.freeze({
__proto__: null,
value: value$1
});

console.log('transform');
const value$2 = 'transform';

var depInlinedViaTransform = /*#__PURE__*/Object.freeze({
__proto__: null,
value: value$2
});
@@ -0,0 +1,4 @@
console.log('not inlined');
const value = 'not inlined';

export { value };
@@ -0,0 +1,30 @@
Promise.resolve().then(function () { return depInlinedViaResolveId; }).then(console.log);
Promise.resolve().then(function () { return depInlinedViaLoad; }).then(console.log);
Promise.resolve().then(function () { return depInlinedViaTransform; }).then(console.log);
import('./generated-dep-not-inlined.js').then(console.log);

console.log('main');

console.log('resolveId');
const value = 'resolveId';

var depInlinedViaResolveId = /*#__PURE__*/Object.freeze({
__proto__: null,
value: value
});

console.log('load');
const value$1 = 'load';

var depInlinedViaLoad = /*#__PURE__*/Object.freeze({
__proto__: null,
value: value$1
});

console.log('transform');
const value$2 = 'transform';

var depInlinedViaTransform = /*#__PURE__*/Object.freeze({
__proto__: null,
value: value$2
});
@@ -0,0 +1,11 @@
System.register([], function (exports) {
'use strict';
return {
execute: function () {

console.log('not inlined');
const value = exports('value', 'not inlined');

}
};
});
@@ -0,0 +1,39 @@
System.register([], function (exports, module) {
'use strict';
return {
execute: function () {

Promise.resolve().then(function () { return depInlinedViaResolveId; }).then(console.log);
Promise.resolve().then(function () { return depInlinedViaLoad; }).then(console.log);
Promise.resolve().then(function () { return depInlinedViaTransform; }).then(console.log);
module.import('./generated-dep-not-inlined.js').then(console.log);

console.log('main');

console.log('resolveId');
const value = 'resolveId';

var depInlinedViaResolveId = /*#__PURE__*/Object.freeze({
__proto__: null,
value: value
});

console.log('load');
const value$1 = 'load';

var depInlinedViaLoad = /*#__PURE__*/Object.freeze({
__proto__: null,
value: value$1
});

console.log('transform');
const value$2 = 'transform';

var depInlinedViaTransform = /*#__PURE__*/Object.freeze({
__proto__: null,
value: value$2
});

}
};
});
@@ -0,0 +1,2 @@
console.log('load');
export const value = 'load';
@@ -0,0 +1,2 @@
console.log('resolveId');
export const value = 'resolveId';
@@ -0,0 +1,2 @@
console.log('transform');
export const value = 'transform';
@@ -0,0 +1,2 @@
console.log('not inlined');
export const value = 'not inlined';
@@ -0,0 +1,6 @@
import('./dep-inlined-via-resolveId.js').then(console.log);
import('./dep-inlined-via-load.js').then(console.log);
import('./dep-inlined-via-transform.js').then(console.log);
import('./dep-not-inlined.js').then(console.log);

console.log('main');

0 comments on commit ce73ae8

Please sign in to comment.