mirror of https://github.com/status-im/metro.git
Backout "Use numeric identifiers when building a bundle"
Summary: public The reverted change doesn’t play nice with inline requires, let’s revert it for now. I will bring it back after fixing it or adapting inline requires Reviewed By: martinbigio Differential Revision: D2854771 fb-gh-sync-id: 32fdbf8ad51240a9075b26502decb6328eed4b29
This commit is contained in:
parent
741cb48fa2
commit
baa6d7fb24
|
@ -41,10 +41,10 @@ class Bundle extends BundleBase {
|
||||||
response,
|
response,
|
||||||
module,
|
module,
|
||||||
transformed.code
|
transformed.code
|
||||||
).then(({code, id}) => {
|
).then(({code, name}) => {
|
||||||
const moduleTransport = new ModuleTransport({
|
const moduleTransport = new ModuleTransport({
|
||||||
code,
|
code,
|
||||||
name: id,
|
name,
|
||||||
map: transformed.map,
|
map: transformed.map,
|
||||||
sourceCode: transformed.sourceCode,
|
sourceCode: transformed.sourceCode,
|
||||||
sourcePath: transformed.sourcePath,
|
sourcePath: transformed.sourcePath,
|
||||||
|
@ -76,7 +76,7 @@ class Bundle extends BundleBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
_addRequireCall(moduleId) {
|
_addRequireCall(moduleId) {
|
||||||
const code = `;require(${JSON.stringify(moduleId)});`;
|
const code = ';require("' + moduleId + '");';
|
||||||
const name = 'require-' + moduleId;
|
const name = 'require-' + moduleId;
|
||||||
super.addModule(new ModuleTransport({
|
super.addModule(new ModuleTransport({
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -10,23 +10,16 @@
|
||||||
|
|
||||||
jest
|
jest
|
||||||
.setMock('worker-farm', () => () => undefined)
|
.setMock('worker-farm', () => () => undefined)
|
||||||
.dontMock('absolute-path')
|
|
||||||
.dontMock('underscore')
|
.dontMock('underscore')
|
||||||
.dontMock('../../lib/ModuleTransport')
|
.dontMock('../../lib/ModuleTransport')
|
||||||
.dontMock('../../DependencyResolver/AssetModule')
|
|
||||||
.dontMock('../../DependencyResolver/Module')
|
|
||||||
.dontMock('../../DependencyResolver/lib/getAssetDataFromName')
|
|
||||||
.setMock('uglify-js')
|
.setMock('uglify-js')
|
||||||
.dontMock('../');
|
.dontMock('../');
|
||||||
|
|
||||||
jest.mock('fs');
|
jest.mock('fs');
|
||||||
|
|
||||||
var AssetModule = require('../../DependencyResolver/AssetModule');
|
|
||||||
var Bundler = require('../');
|
var Bundler = require('../');
|
||||||
var JSTransformer = require('../../JSTransformer');
|
var JSTransformer = require('../../JSTransformer');
|
||||||
var Module = require('../../DependencyResolver/Module');
|
|
||||||
var Resolver = require('../../Resolver');
|
var Resolver = require('../../Resolver');
|
||||||
|
|
||||||
var sizeOf = require('image-size');
|
var sizeOf = require('image-size');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
|
@ -41,14 +34,6 @@ describe('Bundler', function() {
|
||||||
isJSON,
|
isJSON,
|
||||||
resolution,
|
resolution,
|
||||||
}) {
|
}) {
|
||||||
if (isAsset) {
|
|
||||||
const module = new AssetModule({
|
|
||||||
file: path,
|
|
||||||
cache: {get: () => Promise.resolve(path)}
|
|
||||||
});
|
|
||||||
module.getName = () => Promise.resolve(id);
|
|
||||||
return module;
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
path,
|
path,
|
||||||
resolution,
|
resolution,
|
||||||
|
@ -66,8 +51,6 @@ describe('Bundler', function() {
|
||||||
var bundler;
|
var bundler;
|
||||||
var assetServer;
|
var assetServer;
|
||||||
var modules;
|
var modules;
|
||||||
const width = 50;
|
|
||||||
const height = 100;
|
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
getDependencies = jest.genMockFn();
|
getDependencies = jest.genMockFn();
|
||||||
|
@ -125,12 +108,10 @@ describe('Bundler', function() {
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
const mainModule = new Module({file: '/root/foo'});
|
|
||||||
getDependencies.mockImpl(function() {
|
getDependencies.mockImpl(function() {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
mainModuleId: 'foo',
|
mainModuleId: 'foo',
|
||||||
dependencies: modules,
|
dependencies: modules
|
||||||
getMainModule: () => mainModule,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -151,13 +132,12 @@ describe('Bundler', function() {
|
||||||
wrapModule.mockImpl(function(response, module, code) {
|
wrapModule.mockImpl(function(response, module, code) {
|
||||||
return module.getName().then(name => ({
|
return module.getName().then(name => ({
|
||||||
name,
|
name,
|
||||||
id: name,
|
|
||||||
code: 'lol ' + code + ' lol'
|
code: 'lol ' + code + ' lol'
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
sizeOf.mockImpl(function(path, cb) {
|
sizeOf.mockImpl(function(path, cb) {
|
||||||
cb(null, { width, height });
|
cb(null, { width: 50, height: 100 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -207,8 +187,8 @@ describe('Bundler', function() {
|
||||||
__packager_asset: true,
|
__packager_asset: true,
|
||||||
fileSystemLocation: '/root/img',
|
fileSystemLocation: '/root/img',
|
||||||
httpServerLocation: '/assets/img',
|
httpServerLocation: '/assets/img',
|
||||||
width,
|
width: 25,
|
||||||
height,
|
height: 50,
|
||||||
scales: [1, 2, 3],
|
scales: [1, 2, 3],
|
||||||
files: [
|
files: [
|
||||||
'/root/img/img.png',
|
'/root/img/img.png',
|
||||||
|
|
|
@ -102,8 +102,6 @@ class Bundler {
|
||||||
mtime = '';
|
mtime = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
this._getModuleId = createModuleIdGetter();
|
|
||||||
|
|
||||||
this._cache = new Cache({
|
this._cache = new Cache({
|
||||||
resetCache: opts.resetCache,
|
resetCache: opts.resetCache,
|
||||||
cacheKey: [
|
cacheKey: [
|
||||||
|
@ -124,7 +122,6 @@ class Bundler {
|
||||||
fileWatcher: opts.fileWatcher,
|
fileWatcher: opts.fileWatcher,
|
||||||
assetExts: opts.assetExts,
|
assetExts: opts.assetExts,
|
||||||
cache: this._cache,
|
cache: this._cache,
|
||||||
getModuleId: this._getModuleId,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this._bundlesLayout = new BundlesLayout({
|
this._bundlesLayout = new BundlesLayout({
|
||||||
|
@ -190,19 +187,9 @@ class Bundler {
|
||||||
const findEventId = Activity.startEvent('find dependencies');
|
const findEventId = Activity.startEvent('find dependencies');
|
||||||
let transformEventId;
|
let transformEventId;
|
||||||
|
|
||||||
if (isDev) {
|
|
||||||
// `require` calls int the require polyfill itself are not analyzed and
|
|
||||||
// replaced so that they use numeric module IDs. Therefore, we include
|
|
||||||
// the Systrace module before any other module, and it will set itself
|
|
||||||
// as property on the require function.
|
|
||||||
// TODO(davidaurelio) Scan polyfills for dependencies, too (t9759686)
|
|
||||||
runBeforeMainModule = ['Systrace'].concat(runBeforeMainModule);
|
|
||||||
}
|
|
||||||
|
|
||||||
const modulesByName = Object.create(null);
|
|
||||||
return this.getDependencies(entryFile, isDev, platform).then((response) => {
|
return this.getDependencies(entryFile, isDev, platform).then((response) => {
|
||||||
Activity.endEvent(findEventId);
|
Activity.endEvent(findEventId);
|
||||||
bundle.setMainModuleId(this._getModuleId(response.getMainModule()));
|
bundle.setMainModuleId(response.mainModuleId);
|
||||||
transformEventId = Activity.startEvent('transform');
|
transformEventId = Activity.startEvent('transform');
|
||||||
|
|
||||||
const moduleSystemDeps = includeSystemDependencies
|
const moduleSystemDeps = includeSystemDependencies
|
||||||
|
@ -238,11 +225,6 @@ class Bundler {
|
||||||
platform,
|
platform,
|
||||||
hot,
|
hot,
|
||||||
).then(transformed => {
|
).then(transformed => {
|
||||||
return module.getName().then(name => {
|
|
||||||
modulesByName[name] = module;
|
|
||||||
return transformed;
|
|
||||||
});
|
|
||||||
}).then(transformed => {
|
|
||||||
if (bar) {
|
if (bar) {
|
||||||
bar.tick();
|
bar.tick();
|
||||||
}
|
}
|
||||||
|
@ -266,11 +248,7 @@ class Bundler {
|
||||||
));
|
));
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
Activity.endEvent(transformEventId);
|
Activity.endEvent(transformEventId);
|
||||||
const runBeforeIds = runBeforeMainModule
|
bundle.finalize({runBeforeMainModule, runMainModule});
|
||||||
.map(name => modulesByName[name])
|
|
||||||
.filter(Boolean)
|
|
||||||
.map(this._getModuleId, this);
|
|
||||||
bundle.finalize({runBeforeMainModule: runBeforeIds, runMainModule});
|
|
||||||
return bundle;
|
return bundle;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -484,7 +462,8 @@ class Bundler {
|
||||||
type: assetData.type,
|
type: assetData.type,
|
||||||
};
|
};
|
||||||
|
|
||||||
const code = module.getCode(asset);
|
const ASSET_TEMPLATE = 'module.exports = require("AssetRegistry").registerAsset(%json);';
|
||||||
|
const code = ASSET_TEMPLATE.replace('%json', JSON.stringify(asset));
|
||||||
|
|
||||||
return {asset, code};
|
return {asset, code};
|
||||||
});
|
});
|
||||||
|
@ -543,21 +522,12 @@ function verifyRootExists(root) {
|
||||||
assert(fs.statSync(root).isDirectory(), 'Root has to be a valid directory');
|
assert(fs.statSync(root).isDirectory(), 'Root has to be a valid directory');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DummyCache {
|
||||||
|
get(filepath, field, loaderCb) {
|
||||||
|
return loaderCb();
|
||||||
|
}
|
||||||
|
|
||||||
function createModuleIdGetter() {
|
end(){}
|
||||||
const fileToIdMap = Object.create(null);
|
invalidate(filepath){}
|
||||||
let nextId = 0;
|
|
||||||
return (
|
|
||||||
({path}) => {
|
|
||||||
if (!(path in fileToIdMap)) {
|
|
||||||
// can't be a number for now, since we also replace in import / export
|
|
||||||
// we can change that when we eventually change to analyzing dependencies
|
|
||||||
// on transformed modules
|
|
||||||
fileToIdMap[path] = String(nextId++);
|
|
||||||
}
|
|
||||||
return fileToIdMap[path];
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Bundler;
|
module.exports = Bundler;
|
||||||
|
|
|
@ -55,7 +55,6 @@ describe('BundlesLayout', () => {
|
||||||
cache: new Cache(),
|
cache: new Cache(),
|
||||||
assetExts: ['js', 'png'],
|
assetExts: ['js', 'png'],
|
||||||
assetRoots: ['/root'],
|
assetRoots: ['/root'],
|
||||||
getModuleId: () => {},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return new BundlesLayout({
|
return new BundlesLayout({
|
||||||
|
|
|
@ -18,19 +18,13 @@ class AssetModule extends Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
getDependencies() {
|
getDependencies() {
|
||||||
return Promise.resolve(['AssetRegistry']);
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
getAsyncDependencies() {
|
getAsyncDependencies() {
|
||||||
return Promise.resolve([]);
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCode(assetData) {
|
|
||||||
return `module.exports = require('AssetRegistry').registerAsset(${
|
|
||||||
JSON.stringify(assetData)
|
|
||||||
});`;
|
|
||||||
}
|
|
||||||
|
|
||||||
read() {
|
read() {
|
||||||
return Promise.resolve({});
|
return Promise.resolve({});
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,6 @@ class ResolutionResponse {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getMainModule() {
|
|
||||||
this._assertFinalized();
|
|
||||||
return this._mainModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
pushDependency(module) {
|
pushDependency(module) {
|
||||||
this._assertNotFinalized();
|
this._assertNotFinalized();
|
||||||
if (this.dependencies.length === 0) {
|
if (this.dependencies.length === 0) {
|
||||||
|
|
|
@ -374,7 +374,7 @@ describe('DependencyGraph', function() {
|
||||||
{
|
{
|
||||||
id: 'rootPackage/imgs/a.png',
|
id: 'rootPackage/imgs/a.png',
|
||||||
path: '/root/imgs/a.png',
|
path: '/root/imgs/a.png',
|
||||||
dependencies: ['AssetRegistry'],
|
dependencies: [],
|
||||||
isAsset: true,
|
isAsset: true,
|
||||||
resolution: 1,
|
resolution: 1,
|
||||||
isAsset_DEPRECATED: false,
|
isAsset_DEPRECATED: false,
|
||||||
|
@ -434,7 +434,7 @@ describe('DependencyGraph', function() {
|
||||||
id: 'rootPackage/imgs/a.png',
|
id: 'rootPackage/imgs/a.png',
|
||||||
path: '/root/imgs/a@1.5x.png',
|
path: '/root/imgs/a@1.5x.png',
|
||||||
resolution: 1.5,
|
resolution: 1.5,
|
||||||
dependencies: ['AssetRegistry'],
|
dependencies: [],
|
||||||
isAsset: true,
|
isAsset: true,
|
||||||
isAsset_DEPRECATED: false,
|
isAsset_DEPRECATED: false,
|
||||||
isJSON: false,
|
isJSON: false,
|
||||||
|
@ -444,7 +444,7 @@ describe('DependencyGraph', function() {
|
||||||
id: 'rootPackage/imgs/b.png',
|
id: 'rootPackage/imgs/b.png',
|
||||||
path: '/root/imgs/b@.7x.png',
|
path: '/root/imgs/b@.7x.png',
|
||||||
resolution: 0.7,
|
resolution: 0.7,
|
||||||
dependencies: ['AssetRegistry'],
|
dependencies: [],
|
||||||
isAsset: true,
|
isAsset: true,
|
||||||
isAsset_DEPRECATED: false,
|
isAsset_DEPRECATED: false,
|
||||||
isJSON: false,
|
isJSON: false,
|
||||||
|
@ -454,7 +454,7 @@ describe('DependencyGraph', function() {
|
||||||
id: 'rootPackage/imgs/c.png',
|
id: 'rootPackage/imgs/c.png',
|
||||||
path: '/root/imgs/c.png',
|
path: '/root/imgs/c.png',
|
||||||
resolution: 1,
|
resolution: 1,
|
||||||
dependencies: ['AssetRegistry'],
|
dependencies: [],
|
||||||
isAsset: true,
|
isAsset: true,
|
||||||
isAsset_DEPRECATED: false,
|
isAsset_DEPRECATED: false,
|
||||||
isJSON: false,
|
isJSON: false,
|
||||||
|
@ -514,7 +514,7 @@ describe('DependencyGraph', function() {
|
||||||
id: 'rootPackage/imgs/a.png',
|
id: 'rootPackage/imgs/a.png',
|
||||||
path: '/root/imgs/a@1.5x.ios.png',
|
path: '/root/imgs/a@1.5x.ios.png',
|
||||||
resolution: 1.5,
|
resolution: 1.5,
|
||||||
dependencies: ['AssetRegistry'],
|
dependencies: [],
|
||||||
isAsset: true,
|
isAsset: true,
|
||||||
isAsset_DEPRECATED: false,
|
isAsset_DEPRECATED: false,
|
||||||
isJSON: false,
|
isJSON: false,
|
||||||
|
@ -524,7 +524,7 @@ describe('DependencyGraph', function() {
|
||||||
id: 'rootPackage/imgs/b.png',
|
id: 'rootPackage/imgs/b.png',
|
||||||
path: '/root/imgs/b@.7x.ios.png',
|
path: '/root/imgs/b@.7x.ios.png',
|
||||||
resolution: 0.7,
|
resolution: 0.7,
|
||||||
dependencies: ['AssetRegistry'],
|
dependencies: [],
|
||||||
isAsset: true,
|
isAsset: true,
|
||||||
isAsset_DEPRECATED: false,
|
isAsset_DEPRECATED: false,
|
||||||
isJSON: false,
|
isJSON: false,
|
||||||
|
@ -534,7 +534,7 @@ describe('DependencyGraph', function() {
|
||||||
id: 'rootPackage/imgs/c.png',
|
id: 'rootPackage/imgs/c.png',
|
||||||
path: '/root/imgs/c.ios.png',
|
path: '/root/imgs/c.ios.png',
|
||||||
resolution: 1,
|
resolution: 1,
|
||||||
dependencies: ['AssetRegistry'],
|
dependencies: [],
|
||||||
isAsset: true,
|
isAsset: true,
|
||||||
isAsset_DEPRECATED: false,
|
isAsset_DEPRECATED: false,
|
||||||
isJSON: false,
|
isJSON: false,
|
||||||
|
@ -585,7 +585,7 @@ describe('DependencyGraph', function() {
|
||||||
{
|
{
|
||||||
id: 'rootPackage/imgs/a.png',
|
id: 'rootPackage/imgs/a.png',
|
||||||
path: '/root/imgs/a.png',
|
path: '/root/imgs/a.png',
|
||||||
dependencies: ['AssetRegistry'],
|
dependencies: [],
|
||||||
isAsset: true,
|
isAsset: true,
|
||||||
resolution: 1,
|
resolution: 1,
|
||||||
isAsset_DEPRECATED: false,
|
isAsset_DEPRECATED: false,
|
||||||
|
@ -3367,7 +3367,7 @@ describe('DependencyGraph', function() {
|
||||||
{
|
{
|
||||||
id: 'aPackage/foo.png',
|
id: 'aPackage/foo.png',
|
||||||
path: '/root/foo.png',
|
path: '/root/foo.png',
|
||||||
dependencies: ['AssetRegistry'],
|
dependencies: [],
|
||||||
isAsset: true,
|
isAsset: true,
|
||||||
resolution: 1,
|
resolution: 1,
|
||||||
isAsset_DEPRECATED: false,
|
isAsset_DEPRECATED: false,
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
exports.IMPORT_RE = /(\bimport\s*(?:[\s{][^'"]+[\s}]from\s*)??)(['"])([^'"]+)\2()/g;
|
exports.IMPORT_RE = /(\bimport\s+(?:[^'"]+\s+from\s+)??)(['"])([^'"]+)(\2)/g;
|
||||||
exports.EXPORT_RE = /(\bexport\s*(?:[\s{][^'"]+[\s}]from\s*)??)(['"])([^'"]+)\2()/g;
|
exports.EXPORT_RE = /(\bexport\s+(?:[^'"]+\s+from\s+)??)(['"])([^'"]+)(\2)/g;
|
||||||
exports.REQUIRE_RE = /(\brequire\s*?\(\s*?)(['"])([^'"]+)\2(\s*?\))/g;
|
exports.REQUIRE_RE = /(\brequire\s*?\(\s*?)(['"])([^'"]+)(\2\s*?\))/g;
|
||||||
exports.SYSTEM_IMPORT_RE = /(\bSystem\.import\s*?\(\s*?)(['"])([^'"]+)\2(\s*?\))/g;
|
exports.SYSTEM_IMPORT_RE = /(\bSystem\.import\s*?\(\s*?)(['"])([^'"]+)(\2\s*?\))/g;
|
||||||
|
|
|
@ -35,12 +35,6 @@ describe('Resolver', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const modulesWithIds = [];
|
|
||||||
function getModuleId(module) {
|
|
||||||
const index = modulesWithIds.indexOf(module);
|
|
||||||
return String(index !== -1 ? index + 1 : modulesWithIds.push(module));
|
|
||||||
}
|
|
||||||
|
|
||||||
class ResolutionResponseMock {
|
class ResolutionResponseMock {
|
||||||
constructor({dependencies, mainModuleId, asyncDependencies}) {
|
constructor({dependencies, mainModuleId, asyncDependencies}) {
|
||||||
this.dependencies = dependencies;
|
this.dependencies = dependencies;
|
||||||
|
@ -79,7 +73,6 @@ describe('Resolver', function() {
|
||||||
|
|
||||||
var depResolver = new Resolver({
|
var depResolver = new Resolver({
|
||||||
projectRoot: '/root',
|
projectRoot: '/root',
|
||||||
getModuleId,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
DependencyGraph.prototype.getDependencies.mockImpl(function() {
|
DependencyGraph.prototype.getDependencies.mockImpl(function() {
|
||||||
|
@ -167,7 +160,6 @@ describe('Resolver', function() {
|
||||||
|
|
||||||
var depResolver = new Resolver({
|
var depResolver = new Resolver({
|
||||||
projectRoot: '/root',
|
projectRoot: '/root',
|
||||||
getModuleId,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
DependencyGraph.prototype.getDependencies.mockImpl(function() {
|
DependencyGraph.prototype.getDependencies.mockImpl(function() {
|
||||||
|
@ -195,7 +187,6 @@ describe('Resolver', function() {
|
||||||
var depResolver = new Resolver({
|
var depResolver = new Resolver({
|
||||||
projectRoot: '/root',
|
projectRoot: '/root',
|
||||||
polyfillModuleNames: ['some module'],
|
polyfillModuleNames: ['some module'],
|
||||||
getModuleId,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
DependencyGraph.prototype.getDependencies.mockImpl(function() {
|
DependencyGraph.prototype.getDependencies.mockImpl(function() {
|
||||||
|
@ -232,13 +223,12 @@ describe('Resolver', function() {
|
||||||
pit('should resolve modules', function() {
|
pit('should resolve modules', function() {
|
||||||
var depResolver = new Resolver({
|
var depResolver = new Resolver({
|
||||||
projectRoot: '/root',
|
projectRoot: '/root',
|
||||||
getModuleId,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const magicJoiner = '\n\n\n';
|
var dependencies = ['x', 'y', 'z', 'a', 'b'];
|
||||||
|
|
||||||
/*eslint-disable */
|
/*eslint-disable */
|
||||||
const testCases = [
|
var code = [
|
||||||
// single line import
|
// single line import
|
||||||
"import'x';",
|
"import'x';",
|
||||||
"import 'x';",
|
"import 'x';",
|
||||||
|
@ -313,7 +303,6 @@ describe('Resolver', function() {
|
||||||
'import * as All from "x";',
|
'import * as All from "x";',
|
||||||
'import { } from "x";',
|
'import { } from "x";',
|
||||||
'import { Foo } from "x";',
|
'import { Foo } from "x";',
|
||||||
'import{Foo}from"x";',
|
|
||||||
'import { Foo, } from "x";',
|
'import { Foo, } from "x";',
|
||||||
'import { Foo as Bar } from "x";',
|
'import { Foo as Bar } from "x";',
|
||||||
'import { Foo as Bar, } from "x";',
|
'import { Foo as Bar, } from "x";',
|
||||||
|
@ -439,7 +428,6 @@ describe('Resolver', function() {
|
||||||
"export { } from 'x';",
|
"export { } from 'x';",
|
||||||
"export {Foo} from 'x';",
|
"export {Foo} from 'x';",
|
||||||
"export { Foo } from 'x';",
|
"export { Foo } from 'x';",
|
||||||
"export{Foo}from'x';",
|
|
||||||
"export { Foo, } from 'x';",
|
"export { Foo, } from 'x';",
|
||||||
"export {Foo as Bar} from 'x';",
|
"export {Foo as Bar} from 'x';",
|
||||||
"export { Foo as Bar } from 'x';",
|
"export { Foo as Bar } from 'x';",
|
||||||
|
@ -625,9 +613,8 @@ describe('Resolver', function() {
|
||||||
'require( \'z\' )',
|
'require( \'z\' )',
|
||||||
'require( "a")',
|
'require( "a")',
|
||||||
'require("b" )',
|
'require("b" )',
|
||||||
]
|
].join('\n');
|
||||||
/*eslint-disable */
|
/*eslint-disable */
|
||||||
const code = testCases.join(magicJoiner);
|
|
||||||
|
|
||||||
const module = createModule('test module', ['x', 'y']);
|
const module = createModule('test module', ['x', 'y']);
|
||||||
|
|
||||||
|
@ -637,21 +624,11 @@ describe('Resolver', function() {
|
||||||
asyncDependencies: [],
|
asyncDependencies: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const pairs = [
|
resolutionResponse.getResolvedDependencyPairs = (module) => {
|
||||||
['x', createModule('changed')],
|
return [
|
||||||
['y', createModule('Y')],
|
['x', createModule('changed')],
|
||||||
];
|
['y', createModule('Y')],
|
||||||
resolutionResponse.getResolvedDependencyPairs = () => pairs;
|
];
|
||||||
|
|
||||||
function makeExpected(code) {
|
|
||||||
return pairs
|
|
||||||
.reduce((code, [id, module]) =>
|
|
||||||
code.replace(
|
|
||||||
RegExp(`(['"])${id}\\1`),
|
|
||||||
(_, quot) => `${quot}${getModuleId(module)}${quot} /* ${id} */`
|
|
||||||
),
|
|
||||||
code
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return depResolver.wrapModule(
|
return depResolver.wrapModule(
|
||||||
|
@ -660,20 +637,395 @@ describe('Resolver', function() {
|
||||||
code
|
code
|
||||||
).then(processedCode => {
|
).then(processedCode => {
|
||||||
expect(processedCode.name).toEqual('test module');
|
expect(processedCode.name).toEqual('test module');
|
||||||
|
expect(processedCode.code).toEqual([
|
||||||
// extract the converted code from the module wrapper
|
'__d(\'test module\',function(global, require,' +
|
||||||
const cases =
|
' module, exports) { ' +
|
||||||
processedCode.code
|
// single line import
|
||||||
.match(/__d\(.*?\{\s*([\s\S]*)\}/)[1] // match code in wrapper
|
"import'x';",
|
||||||
.replace(/\s+$/, '') // remove trailing whitespace
|
"import 'changed';",
|
||||||
.split(magicJoiner); // extract every tested case
|
"import 'changed' ;",
|
||||||
|
"import Default from 'changed';",
|
||||||
testCases.forEach((inputCode, i) => {
|
"import * as All from 'changed';",
|
||||||
expect(cases[i]).toEqual(makeExpected(inputCode));
|
"import {} from 'changed';",
|
||||||
if(cases[i]!==makeExpected(inputCode)) {
|
"import { } from 'changed';",
|
||||||
console.log('FAIL %s: input(%s) expected(%s) actual(%s)', i, inputCode, makeExpected(inputCode), cases[i]);
|
"import {Foo} from 'changed';",
|
||||||
}
|
"import { Foo } from 'changed';",
|
||||||
});
|
"import { Foo, } from 'changed';",
|
||||||
|
"import {Foo as Bar} from 'changed';",
|
||||||
|
"import { Foo as Bar } from 'changed';",
|
||||||
|
"import { Foo as Bar, } from 'changed';",
|
||||||
|
"import { Foo, Bar } from 'changed';",
|
||||||
|
"import { Foo, Bar, } from 'changed';",
|
||||||
|
"import { Foo as Bar, Baz } from 'changed';",
|
||||||
|
"import { Foo as Bar, Baz, } from 'changed';",
|
||||||
|
"import { Foo, Bar as Baz } from 'changed';",
|
||||||
|
"import { Foo, Bar as Baz, } from 'changed';",
|
||||||
|
"import { Foo as Bar, Baz as Qux } from 'changed';",
|
||||||
|
"import { Foo as Bar, Baz as Qux, } from 'changed';",
|
||||||
|
"import { Foo, Bar, Baz } from 'changed';",
|
||||||
|
"import { Foo, Bar, Baz, } from 'changed';",
|
||||||
|
"import { Foo as Bar, Baz, Qux } from 'changed';",
|
||||||
|
"import { Foo as Bar, Baz, Qux, } from 'changed';",
|
||||||
|
"import { Foo, Bar as Baz, Qux } from 'changed';",
|
||||||
|
"import { Foo, Bar as Baz, Qux, } from 'changed';",
|
||||||
|
"import { Foo, Bar, Baz as Qux } from 'changed';",
|
||||||
|
"import { Foo, Bar, Baz as Qux, } from 'changed';",
|
||||||
|
"import { Foo as Bar, Baz as Qux, Norf } from 'changed';",
|
||||||
|
"import { Foo as Bar, Baz as Qux, Norf, } from 'changed';",
|
||||||
|
"import { Foo as Bar, Baz, Qux as Norf } from 'changed';",
|
||||||
|
"import { Foo as Bar, Baz, Qux as Norf, } from 'changed';",
|
||||||
|
"import { Foo, Bar as Baz, Qux as Norf } from 'changed';",
|
||||||
|
"import { Foo, Bar as Baz, Qux as Norf, } from 'changed';",
|
||||||
|
"import { Foo as Bar, Baz as Qux, Norf as Enuf } from 'changed';",
|
||||||
|
"import { Foo as Bar, Baz as Qux, Norf as Enuf, } from 'changed';",
|
||||||
|
"import Default, * as All from 'changed';",
|
||||||
|
"import Default, { } from 'changed';",
|
||||||
|
"import Default, { Foo } from 'changed';",
|
||||||
|
"import Default, { Foo, } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar, } from 'changed';",
|
||||||
|
"import Default, { Foo, Bar } from 'changed';",
|
||||||
|
"import Default, { Foo, Bar, } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar, Baz } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar, Baz, } from 'changed';",
|
||||||
|
"import Default, { Foo, Bar as Baz } from 'changed';",
|
||||||
|
"import Default, { Foo, Bar as Baz, } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar, Baz as Qux } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar, Baz as Qux, } from 'changed';",
|
||||||
|
"import Default, { Foo, Bar, Baz } from 'changed';",
|
||||||
|
"import Default, { Foo, Bar, Baz, } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar, Baz, Qux } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar, Baz, Qux, } from 'changed';",
|
||||||
|
"import Default, { Foo, Bar as Baz, Qux } from 'changed';",
|
||||||
|
"import Default, { Foo, Bar as Baz, Qux, } from 'changed';",
|
||||||
|
"import Default, { Foo, Bar, Baz as Qux } from 'changed';",
|
||||||
|
"import Default, { Foo, Bar, Baz as Qux, } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar, Baz as Qux, Norf } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar, Baz as Qux, Norf, } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar, Baz, Qux as Norf } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar, Baz, Qux as Norf, } from 'changed';",
|
||||||
|
"import Default, { Foo, Bar as Baz, Qux as Norf } from 'changed';",
|
||||||
|
"import Default, { Foo, Bar as Baz, Qux as Norf, } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar, Baz as Qux, Norf as NoMore } from 'changed';",
|
||||||
|
"import Default, { Foo as Bar, Baz as Qux, Norf as NoMore, } from 'changed';",
|
||||||
|
"import Default , { } from 'changed';",
|
||||||
|
'import "changed";',
|
||||||
|
'import Default from "changed";',
|
||||||
|
'import * as All from "changed";',
|
||||||
|
'import { } from "changed";',
|
||||||
|
'import { Foo } from "changed";',
|
||||||
|
'import { Foo, } from "changed";',
|
||||||
|
'import { Foo as Bar } from "changed";',
|
||||||
|
'import { Foo as Bar, } from "changed";',
|
||||||
|
'import { Foo, Bar } from "changed";',
|
||||||
|
'import { Foo, Bar, } from "changed";',
|
||||||
|
'import { Foo as Bar, Baz } from "changed";',
|
||||||
|
'import { Foo as Bar, Baz, } from "changed";',
|
||||||
|
'import { Foo, Bar as Baz } from "changed";',
|
||||||
|
'import { Foo, Bar as Baz, } from "changed";',
|
||||||
|
'import { Foo as Bar, Baz as Qux } from "changed";',
|
||||||
|
'import { Foo as Bar, Baz as Qux, } from "changed";',
|
||||||
|
'import { Foo, Bar, Baz } from "changed";',
|
||||||
|
'import { Foo, Bar, Baz, } from "changed";',
|
||||||
|
'import { Foo as Bar, Baz, Qux } from "changed";',
|
||||||
|
'import { Foo as Bar, Baz, Qux, } from "changed";',
|
||||||
|
'import { Foo, Bar as Baz, Qux } from "changed";',
|
||||||
|
'import { Foo, Bar as Baz, Qux, } from "changed";',
|
||||||
|
'import { Foo, Bar, Baz as Qux } from "changed";',
|
||||||
|
'import { Foo, Bar, Baz as Qux, } from "changed";',
|
||||||
|
'import { Foo as Bar, Baz as Qux, Norf } from "changed";',
|
||||||
|
'import { Foo as Bar, Baz as Qux, Norf, } from "changed";',
|
||||||
|
'import { Foo as Bar, Baz, Qux as Norf } from "changed";',
|
||||||
|
'import { Foo as Bar, Baz, Qux as Norf, } from "changed";',
|
||||||
|
'import { Foo, Bar as Baz, Qux as Norf } from "changed";',
|
||||||
|
'import { Foo, Bar as Baz, Qux as Norf, } from "changed";',
|
||||||
|
'import { Foo as Bar, Baz as Qux, Norf as NoMore } from "changed";',
|
||||||
|
'import { Foo as Bar, Baz as Qux, Norf as NoMore, } from "changed";',
|
||||||
|
'import Default, * as All from "changed";',
|
||||||
|
'import Default, { } from "changed";',
|
||||||
|
'import Default, { Foo } from "changed";',
|
||||||
|
'import Default, { Foo, } from "changed";',
|
||||||
|
'import Default, { Foo as Bar } from "changed";',
|
||||||
|
'import Default, { Foo as Bar, } from "changed";',
|
||||||
|
'import Default, { Foo, Bar } from "changed";',
|
||||||
|
'import Default, { Foo, Bar, } from "changed";',
|
||||||
|
'import Default, { Foo as Bar, Baz } from "changed";',
|
||||||
|
'import Default, { Foo as Bar, Baz, } from "changed";',
|
||||||
|
'import Default, { Foo, Bar as Baz } from "changed";',
|
||||||
|
'import Default, { Foo, Bar as Baz, } from "changed";',
|
||||||
|
'import Default, { Foo as Bar, Baz as Qux } from "changed";',
|
||||||
|
'import Default, { Foo as Bar, Baz as Qux, } from "changed";',
|
||||||
|
'import Default, { Foo, Bar, Baz } from "changed";',
|
||||||
|
'import Default, { Foo, Bar, Baz, } from "changed";',
|
||||||
|
'import Default, { Foo as Bar, Baz, Qux } from "changed";',
|
||||||
|
'import Default, { Foo as Bar, Baz, Qux, } from "changed";',
|
||||||
|
'import Default, { Foo, Bar as Baz, Qux } from "changed";',
|
||||||
|
'import Default, { Foo, Bar as Baz, Qux, } from "changed";',
|
||||||
|
'import Default, { Foo, Bar, Baz as Qux } from "changed";',
|
||||||
|
'import Default, { Foo, Bar, Baz as Qux, } from "changed";',
|
||||||
|
'import Default, { Foo as Bar, Baz as Qux, Norf } from "changed";',
|
||||||
|
'import Default, { Foo as Bar, Baz as Qux, Norf, } from "changed";',
|
||||||
|
'import Default, { Foo as Bar, Baz, Qux as Norf } from "changed";',
|
||||||
|
'import Default, { Foo as Bar, Baz, Qux as Norf, } from "changed";',
|
||||||
|
'import Default, { Foo, Bar as Baz, Qux as Norf } from "changed";',
|
||||||
|
'import Default, { Foo, Bar as Baz, Qux as Norf, } from "changed";',
|
||||||
|
'import Default, { Foo as Bar, Baz as Qux, Norf as Enuf } from "changed";',
|
||||||
|
'import Default, { Foo as Bar, Baz as Qux, Norf as Enuf, } from "changed";',
|
||||||
|
'import Default from "Y";',
|
||||||
|
'import * as All from \'z\';',
|
||||||
|
// import with support for new lines
|
||||||
|
"import { Foo,\n Bar }\n from 'changed';",
|
||||||
|
"import { \nFoo,\nBar,\n }\n from 'changed';",
|
||||||
|
"import { Foo as Bar,\n Baz\n }\n from 'changed';",
|
||||||
|
"import { \nFoo as Bar,\n Baz\n, }\n from 'changed';",
|
||||||
|
"import { Foo,\n Bar as Baz\n }\n from 'changed';",
|
||||||
|
"import { Foo,\n Bar as Baz,\n }\n from 'changed';",
|
||||||
|
"import { Foo as Bar,\n Baz as Qux\n }\n from 'changed';",
|
||||||
|
"import { Foo as Bar,\n Baz as Qux,\n }\n from 'changed';",
|
||||||
|
"import { Foo,\n Bar,\n Baz }\n from 'changed';",
|
||||||
|
"import { Foo,\n Bar,\n Baz,\n }\n from 'changed';",
|
||||||
|
"import { Foo as Bar,\n Baz,\n Qux\n }\n from 'changed';",
|
||||||
|
"import { Foo as Bar,\n Baz,\n Qux,\n }\n from 'changed';",
|
||||||
|
"import { Foo,\n Bar as Baz,\n Qux\n }\n from 'changed';",
|
||||||
|
"import { Foo,\n Bar as Baz,\n Qux,\n }\n from 'changed';",
|
||||||
|
"import { Foo,\n Bar,\n Baz as Qux\n }\n from 'changed';",
|
||||||
|
"import { Foo,\n Bar,\n Baz as Qux,\n }\n from 'changed';",
|
||||||
|
"import { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'changed';",
|
||||||
|
"import { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'changed';",
|
||||||
|
"import { Foo as Bar,\n Baz,\n Qux as Norf\n }\n from 'changed';",
|
||||||
|
"import { Foo as Bar,\n Baz,\n Qux as Norf,\n }\n from 'changed';",
|
||||||
|
"import { Foo,\n Bar as Baz,\n Qux as Norf\n }\n from 'changed';",
|
||||||
|
"import { Foo,\n Bar as Baz,\n Qux as Norf,\n }\n from 'changed';",
|
||||||
|
"import { Foo as Bar,\n Baz as Qux,\n Norf as Enuf\n }\n from 'changed';",
|
||||||
|
"import { Foo as Bar,\n Baz as Qux,\n Norf as Enuf,\n }\n from 'changed';",
|
||||||
|
"import Default,\n * as All from 'changed';",
|
||||||
|
"import Default,\n { } from 'changed';",
|
||||||
|
"import Default,\n { Foo\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo,\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar,\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo,\n Bar\n } from\n 'changed';",
|
||||||
|
"import Default,\n { Foo,\n Bar,\n } from\n 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar,\n Baz\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar,\n Baz,\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo,\n Bar as Baz\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo,\n Bar as Baz,\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar,\n Baz as Qux\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar,\n Baz as Qux,\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo,\n Bar,\n Baz\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo,\n Bar,\n Baz,\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar,\n Baz,\n Qux\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar,\n Baz,\n Qux,\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo,\n Bar as Baz,\n Qux\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo,\n Bar as Baz,\n Qux,\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo,\n Bar,\n Baz as Qux\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo,\n Bar,\n Baz as Qux,\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar,\n Baz,\n Qux as Norf }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar,\n Baz,\n Qux as Norf, }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo, Bar as Baz,\n Qux as Norf }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo, Bar as Baz,\n Qux as Norf, }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore\n }\n from 'changed';",
|
||||||
|
"import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore,\n }\n from 'changed';",
|
||||||
|
"import Default\n , { } from 'changed';",
|
||||||
|
// single line export
|
||||||
|
"export'x';",
|
||||||
|
"export 'changed';",
|
||||||
|
"export 'changed' ;",
|
||||||
|
"export Default from 'changed';",
|
||||||
|
"export * as All from 'changed';",
|
||||||
|
"export {} from 'changed';",
|
||||||
|
"export { } from 'changed';",
|
||||||
|
"export {Foo} from 'changed';",
|
||||||
|
"export { Foo } from 'changed';",
|
||||||
|
"export { Foo, } from 'changed';",
|
||||||
|
"export {Foo as Bar} from 'changed';",
|
||||||
|
"export { Foo as Bar } from 'changed';",
|
||||||
|
"export { Foo as Bar, } from 'changed';",
|
||||||
|
"export { Foo, Bar } from 'changed';",
|
||||||
|
"export { Foo, Bar, } from 'changed';",
|
||||||
|
"export { Foo as Bar, Baz } from 'changed';",
|
||||||
|
"export { Foo as Bar, Baz, } from 'changed';",
|
||||||
|
"export { Foo, Bar as Baz } from 'changed';",
|
||||||
|
"export { Foo, Bar as Baz, } from 'changed';",
|
||||||
|
"export { Foo as Bar, Baz as Qux } from 'changed';",
|
||||||
|
"export { Foo as Bar, Baz as Qux, } from 'changed';",
|
||||||
|
"export { Foo, Bar, Baz } from 'changed';",
|
||||||
|
"export { Foo, Bar, Baz, } from 'changed';",
|
||||||
|
"export { Foo as Bar, Baz, Qux } from 'changed';",
|
||||||
|
"export { Foo as Bar, Baz, Qux, } from 'changed';",
|
||||||
|
"export { Foo, Bar as Baz, Qux } from 'changed';",
|
||||||
|
"export { Foo, Bar as Baz, Qux, } from 'changed';",
|
||||||
|
"export { Foo, Bar, Baz as Qux } from 'changed';",
|
||||||
|
"export { Foo, Bar, Baz as Qux, } from 'changed';",
|
||||||
|
"export { Foo as Bar, Baz as Qux, Norf } from 'changed';",
|
||||||
|
"export { Foo as Bar, Baz as Qux, Norf, } from 'changed';",
|
||||||
|
"export { Foo as Bar, Baz, Qux as Norf } from 'changed';",
|
||||||
|
"export { Foo as Bar, Baz, Qux as Norf, } from 'changed';",
|
||||||
|
"export { Foo, Bar as Baz, Qux as Norf } from 'changed';",
|
||||||
|
"export { Foo, Bar as Baz, Qux as Norf, } from 'changed';",
|
||||||
|
"export { Foo as Bar, Baz as Qux, Norf as Enuf } from 'changed';",
|
||||||
|
"export { Foo as Bar, Baz as Qux, Norf as Enuf, } from 'changed';",
|
||||||
|
"export Default, * as All from 'changed';",
|
||||||
|
"export Default, { } from 'changed';",
|
||||||
|
"export Default, { Foo } from 'changed';",
|
||||||
|
"export Default, { Foo, } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar, } from 'changed';",
|
||||||
|
"export Default, { Foo, Bar } from 'changed';",
|
||||||
|
"export Default, { Foo, Bar, } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar, Baz } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar, Baz, } from 'changed';",
|
||||||
|
"export Default, { Foo, Bar as Baz } from 'changed';",
|
||||||
|
"export Default, { Foo, Bar as Baz, } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar, Baz as Qux } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar, Baz as Qux, } from 'changed';",
|
||||||
|
"export Default, { Foo, Bar, Baz } from 'changed';",
|
||||||
|
"export Default, { Foo, Bar, Baz, } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar, Baz, Qux } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar, Baz, Qux, } from 'changed';",
|
||||||
|
"export Default, { Foo, Bar as Baz, Qux } from 'changed';",
|
||||||
|
"export Default, { Foo, Bar as Baz, Qux, } from 'changed';",
|
||||||
|
"export Default, { Foo, Bar, Baz as Qux } from 'changed';",
|
||||||
|
"export Default, { Foo, Bar, Baz as Qux, } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar, Baz as Qux, Norf } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar, Baz as Qux, Norf, } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar, Baz, Qux as Norf } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar, Baz, Qux as Norf, } from 'changed';",
|
||||||
|
"export Default, { Foo, Bar as Baz, Qux as Norf } from 'changed';",
|
||||||
|
"export Default, { Foo, Bar as Baz, Qux as Norf, } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar, Baz as Qux, Norf as NoMore } from 'changed';",
|
||||||
|
"export Default, { Foo as Bar, Baz as Qux, Norf as NoMore, } from 'changed';",
|
||||||
|
"export Default , { } from 'changed';",
|
||||||
|
'export "changed";',
|
||||||
|
'export Default from "changed";',
|
||||||
|
'export * as All from "changed";',
|
||||||
|
'export { } from "changed";',
|
||||||
|
'export { Foo } from "changed";',
|
||||||
|
'export { Foo, } from "changed";',
|
||||||
|
'export { Foo as Bar } from "changed";',
|
||||||
|
'export { Foo as Bar, } from "changed";',
|
||||||
|
'export { Foo, Bar } from "changed";',
|
||||||
|
'export { Foo, Bar, } from "changed";',
|
||||||
|
'export { Foo as Bar, Baz } from "changed";',
|
||||||
|
'export { Foo as Bar, Baz, } from "changed";',
|
||||||
|
'export { Foo, Bar as Baz } from "changed";',
|
||||||
|
'export { Foo, Bar as Baz, } from "changed";',
|
||||||
|
'export { Foo as Bar, Baz as Qux } from "changed";',
|
||||||
|
'export { Foo as Bar, Baz as Qux, } from "changed";',
|
||||||
|
'export { Foo, Bar, Baz } from "changed";',
|
||||||
|
'export { Foo, Bar, Baz, } from "changed";',
|
||||||
|
'export { Foo as Bar, Baz, Qux } from "changed";',
|
||||||
|
'export { Foo as Bar, Baz, Qux, } from "changed";',
|
||||||
|
'export { Foo, Bar as Baz, Qux } from "changed";',
|
||||||
|
'export { Foo, Bar as Baz, Qux, } from "changed";',
|
||||||
|
'export { Foo, Bar, Baz as Qux } from "changed";',
|
||||||
|
'export { Foo, Bar, Baz as Qux, } from "changed";',
|
||||||
|
'export { Foo as Bar, Baz as Qux, Norf } from "changed";',
|
||||||
|
'export { Foo as Bar, Baz as Qux, Norf, } from "changed";',
|
||||||
|
'export { Foo as Bar, Baz, Qux as Norf } from "changed";',
|
||||||
|
'export { Foo as Bar, Baz, Qux as Norf, } from "changed";',
|
||||||
|
'export { Foo, Bar as Baz, Qux as Norf } from "changed";',
|
||||||
|
'export { Foo, Bar as Baz, Qux as Norf, } from "changed";',
|
||||||
|
'export { Foo as Bar, Baz as Qux, Norf as NoMore } from "changed";',
|
||||||
|
'export { Foo as Bar, Baz as Qux, Norf as NoMore, } from "changed";',
|
||||||
|
'export Default, * as All from "changed";',
|
||||||
|
'export Default, { } from "changed";',
|
||||||
|
'export Default, { Foo } from "changed";',
|
||||||
|
'export Default, { Foo, } from "changed";',
|
||||||
|
'export Default, { Foo as Bar } from "changed";',
|
||||||
|
'export Default, { Foo as Bar, } from "changed";',
|
||||||
|
'export Default, { Foo, Bar } from "changed";',
|
||||||
|
'export Default, { Foo, Bar, } from "changed";',
|
||||||
|
'export Default, { Foo as Bar, Baz } from "changed";',
|
||||||
|
'export Default, { Foo as Bar, Baz, } from "changed";',
|
||||||
|
'export Default, { Foo, Bar as Baz } from "changed";',
|
||||||
|
'export Default, { Foo, Bar as Baz, } from "changed";',
|
||||||
|
'export Default, { Foo as Bar, Baz as Qux } from "changed";',
|
||||||
|
'export Default, { Foo as Bar, Baz as Qux, } from "changed";',
|
||||||
|
'export Default, { Foo, Bar, Baz } from "changed";',
|
||||||
|
'export Default, { Foo, Bar, Baz, } from "changed";',
|
||||||
|
'export Default, { Foo as Bar, Baz, Qux } from "changed";',
|
||||||
|
'export Default, { Foo as Bar, Baz, Qux, } from "changed";',
|
||||||
|
'export Default, { Foo, Bar as Baz, Qux } from "changed";',
|
||||||
|
'export Default, { Foo, Bar as Baz, Qux, } from "changed";',
|
||||||
|
'export Default, { Foo, Bar, Baz as Qux } from "changed";',
|
||||||
|
'export Default, { Foo, Bar, Baz as Qux, } from "changed";',
|
||||||
|
'export Default, { Foo as Bar, Baz as Qux, Norf } from "changed";',
|
||||||
|
'export Default, { Foo as Bar, Baz as Qux, Norf, } from "changed";',
|
||||||
|
'export Default, { Foo as Bar, Baz, Qux as Norf } from "changed";',
|
||||||
|
'export Default, { Foo as Bar, Baz, Qux as Norf, } from "changed";',
|
||||||
|
'export Default, { Foo, Bar as Baz, Qux as Norf } from "changed";',
|
||||||
|
'export Default, { Foo, Bar as Baz, Qux as Norf, } from "changed";',
|
||||||
|
'export Default, { Foo as Bar, Baz as Qux, Norf as Enuf } from "changed";',
|
||||||
|
'export Default, { Foo as Bar, Baz as Qux, Norf as Enuf, } from "changed";',
|
||||||
|
'export Default from "Y";',
|
||||||
|
'export * as All from \'z\';',
|
||||||
|
// export with support for new lines
|
||||||
|
"export { Foo,\n Bar }\n from 'changed';",
|
||||||
|
"export { \nFoo,\nBar,\n }\n from 'changed';",
|
||||||
|
"export { Foo as Bar,\n Baz\n }\n from 'changed';",
|
||||||
|
"export { \nFoo as Bar,\n Baz\n, }\n from 'changed';",
|
||||||
|
"export { Foo,\n Bar as Baz\n }\n from 'changed';",
|
||||||
|
"export { Foo,\n Bar as Baz,\n }\n from 'changed';",
|
||||||
|
"export { Foo as Bar,\n Baz as Qux\n }\n from 'changed';",
|
||||||
|
"export { Foo as Bar,\n Baz as Qux,\n }\n from 'changed';",
|
||||||
|
"export { Foo,\n Bar,\n Baz }\n from 'changed';",
|
||||||
|
"export { Foo,\n Bar,\n Baz,\n }\n from 'changed';",
|
||||||
|
"export { Foo as Bar,\n Baz,\n Qux\n }\n from 'changed';",
|
||||||
|
"export { Foo as Bar,\n Baz,\n Qux,\n }\n from 'changed';",
|
||||||
|
"export { Foo,\n Bar as Baz,\n Qux\n }\n from 'changed';",
|
||||||
|
"export { Foo,\n Bar as Baz,\n Qux,\n }\n from 'changed';",
|
||||||
|
"export { Foo,\n Bar,\n Baz as Qux\n }\n from 'changed';",
|
||||||
|
"export { Foo,\n Bar,\n Baz as Qux,\n }\n from 'changed';",
|
||||||
|
"export { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'changed';",
|
||||||
|
"export { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'changed';",
|
||||||
|
"export { Foo as Bar,\n Baz,\n Qux as Norf\n }\n from 'changed';",
|
||||||
|
"export { Foo as Bar,\n Baz,\n Qux as Norf,\n }\n from 'changed';",
|
||||||
|
"export { Foo,\n Bar as Baz,\n Qux as Norf\n }\n from 'changed';",
|
||||||
|
"export { Foo,\n Bar as Baz,\n Qux as Norf,\n }\n from 'changed';",
|
||||||
|
"export { Foo as Bar,\n Baz as Qux,\n Norf as Enuf\n }\n from 'changed';",
|
||||||
|
"export { Foo as Bar,\n Baz as Qux,\n Norf as Enuf,\n }\n from 'changed';",
|
||||||
|
"export Default,\n * as All from 'changed';",
|
||||||
|
"export Default,\n { } from 'changed';",
|
||||||
|
"export Default,\n { Foo\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo,\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar,\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo,\n Bar\n } from\n 'changed';",
|
||||||
|
"export Default,\n { Foo,\n Bar,\n } from\n 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar,\n Baz\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar,\n Baz,\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo,\n Bar as Baz\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo,\n Bar as Baz,\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar,\n Baz as Qux\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar,\n Baz as Qux,\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo,\n Bar,\n Baz\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo,\n Bar,\n Baz,\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar,\n Baz,\n Qux\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar,\n Baz,\n Qux,\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo,\n Bar as Baz,\n Qux\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo,\n Bar as Baz,\n Qux,\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo,\n Bar,\n Baz as Qux\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo,\n Bar,\n Baz as Qux,\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar,\n Baz,\n Qux as Norf }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar,\n Baz,\n Qux as Norf, }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo, Bar as Baz,\n Qux as Norf }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo, Bar as Baz,\n Qux as Norf, }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore\n }\n from 'changed';",
|
||||||
|
"export Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore,\n }\n from 'changed';",
|
||||||
|
"export Default\n , { } from 'changed';",
|
||||||
|
// require
|
||||||
|
'require("changed")',
|
||||||
|
'require("Y")',
|
||||||
|
'require( \'z\' )',
|
||||||
|
'require( "a")',
|
||||||
|
'require("b" )',
|
||||||
|
'});',
|
||||||
|
].join('\n'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,6 @@ const validateOpts = declareOpts({
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
getModuleId: {
|
|
||||||
type: 'function',
|
|
||||||
required: true,
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const getDependenciesValidateOpts = declareOpts({
|
const getDependenciesValidateOpts = declareOpts({
|
||||||
|
@ -102,7 +98,6 @@ class Resolver {
|
||||||
shouldThrowOnUnresolvedErrors: (_, platform) => platform === 'ios',
|
shouldThrowOnUnresolvedErrors: (_, platform) => platform === 'ios',
|
||||||
});
|
});
|
||||||
|
|
||||||
this._getModuleId = options.getModuleId;
|
|
||||||
this._polyfillModuleNames = opts.polyfillModuleNames || [];
|
this._polyfillModuleNames = opts.polyfillModuleNames || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,32 +177,36 @@ class Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolvedDeps = Object.create(null);
|
const resolvedDeps = Object.create(null);
|
||||||
|
const resolvedDepsArr = [];
|
||||||
|
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
resolutionResponse.getResolvedDependencyPairs(module).map(
|
resolutionResponse.getResolvedDependencyPairs(module).map(
|
||||||
([depName, depModule]) => {
|
([depName, depModule]) => {
|
||||||
if (depModule) {
|
if (depModule) {
|
||||||
resolvedDeps[depName] = this._getModuleId(depModule);
|
return depModule.getName().then(name => {
|
||||||
|
resolvedDeps[depName] = name;
|
||||||
|
resolvedDepsArr.push(name);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
).then(() => {
|
).then(() => {
|
||||||
const replaceModuleId = (codeMatch, pre, quot, depName, post = '') => {
|
const relativizeCode = (codeMatch, pre, quot, depName, post) => {
|
||||||
if (depName in resolvedDeps) {
|
const depId = resolvedDeps[depName];
|
||||||
const replacement = `${quot}${resolvedDeps[depName]}${quot}`;
|
if (depId) {
|
||||||
return `${pre}${replacement} /* ${depName} */${post}`;
|
return pre + quot + depId + post;
|
||||||
} else {
|
} else {
|
||||||
return codeMatch;
|
return codeMatch;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
code = code
|
code = code
|
||||||
.replace(replacePatterns.IMPORT_RE, replaceModuleId)
|
.replace(replacePatterns.IMPORT_RE, relativizeCode)
|
||||||
.replace(replacePatterns.EXPORT_RE, replaceModuleId)
|
.replace(replacePatterns.EXPORT_RE, relativizeCode)
|
||||||
.replace(replacePatterns.REQUIRE_RE, replaceModuleId);
|
.replace(replacePatterns.REQUIRE_RE, relativizeCode);
|
||||||
|
|
||||||
return module.getName().then(name => {
|
return module.getName().then(name => {
|
||||||
return {name, code, id: this._getModuleId(module)};
|
return {name, code};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -221,8 +220,8 @@ class Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.resolveRequires(resolutionResponse, module, code).then(
|
return this.resolveRequires(resolutionResponse, module, code).then(
|
||||||
({name, code, id}) => {
|
({name, code}) => {
|
||||||
return {id, name, code: defineModuleCode(id, code, name)};
|
return {name, code: defineModuleCode(name, code)};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,10 +231,10 @@ class Resolver {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function defineModuleCode(moduleId, code, verboseName = '') {
|
function defineModuleCode(moduleName, code) {
|
||||||
return [
|
return [
|
||||||
`__d(`,
|
`__d(`,
|
||||||
`${JSON.stringify(moduleId)} /* ${verboseName} */ ,`,
|
`'${moduleName}',`,
|
||||||
'function(global, require, module, exports) {',
|
'function(global, require, module, exports) {',
|
||||||
` ${code}`,
|
` ${code}`,
|
||||||
'\n});',
|
'\n});',
|
||||||
|
|
|
@ -59,29 +59,18 @@ function requireImpl(id) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// `require` calls int the require polyfill itself are not analyzed and
|
|
||||||
// replaced so that they use numeric module IDs.
|
|
||||||
// The systrace module will expose itself on the require function so that
|
|
||||||
// it can be used here.
|
|
||||||
// TODO(davidaurelio) Scan polyfills for dependencies, too (t9759686)
|
|
||||||
const {Systrace} = require;
|
|
||||||
try {
|
try {
|
||||||
// We must optimistically mark mod as initialized before running the factory to keep any
|
// We must optimistically mark mod as initialized before running the factory to keep any
|
||||||
// require cycles inside the factory from causing an infinite require loop.
|
// require cycles inside the factory from causing an infinite require loop.
|
||||||
mod.isInitialized = true;
|
mod.isInitialized = true;
|
||||||
|
|
||||||
if (__DEV__) {
|
__DEV__ && Systrace().beginEvent('JS_require_' + id);
|
||||||
Systrace.beginEvent('JS_require_' + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// keep args in sync with with defineModuleCode in
|
// keep args in sync with with defineModuleCode in
|
||||||
// packager/react-packager/src/Resolver/index.js
|
// packager/react-packager/src/Resolver/index.js
|
||||||
mod.factory.call(global, global, require, mod.module, mod.module.exports);
|
mod.factory.call(global, global, require, mod.module, mod.module.exports);
|
||||||
|
|
||||||
if (__DEV__) {
|
__DEV__ && Systrace().endEvent();
|
||||||
Systrace.endEvent();
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
mod.hasError = true;
|
mod.hasError = true;
|
||||||
mod.isInitialized = false;
|
mod.isInitialized = false;
|
||||||
|
@ -91,9 +80,15 @@ function requireImpl(id) {
|
||||||
return mod.module.exports;
|
return mod.module.exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__DEV__) {
|
const Systrace = __DEV__ && (() => {
|
||||||
require.Systrace = { beginEvent: () => {}, endEvent: () => {} };
|
var _Systrace;
|
||||||
}
|
try {
|
||||||
|
_Systrace = require('Systrace');
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
return _Systrace && _Systrace.beginEvent ?
|
||||||
|
_Systrace : { beginEvent: () => {}, endEvent: () => {} };
|
||||||
|
});
|
||||||
|
|
||||||
global.__d = define;
|
global.__d = define;
|
||||||
global.require = require;
|
global.require = require;
|
||||||
|
|
Loading…
Reference in New Issue