mirror of https://github.com/status-im/metro.git
react-packager: Add ES6 import statement support to DependencyGraph.
Summary: This PR teaches packager's `DependencyGraph` how to extract dependencies written with ES6 `import` statements. It fixes the issue where you are not able to write your app with ES6 `import` statements when your custom transformer (replacing the default [JSTransform](https://github.com/facebook/jstransform), for example, [babel](http://babeljs.io/)) already supports the ES6 `import` syntax. It will also be useful for [JSTransform](https://github.com/facebook/jstransform) later on once it implements `import` feature too. Closes https://github.com/facebook/react-native/pull/386 Github Author: Pilwon Huh <pilwon@gmail.com> Test Plan: runJestTests.sh
This commit is contained in:
parent
461f169a9e
commit
d476461120
|
@ -13,7 +13,7 @@ jest
|
||||||
.dontMock('path')
|
.dontMock('path')
|
||||||
.dontMock('absolute-path')
|
.dontMock('absolute-path')
|
||||||
.dontMock('../docblock')
|
.dontMock('../docblock')
|
||||||
.dontMock('../../requirePattern')
|
.dontMock('../../replacePatterns')
|
||||||
.setMock('../../../ModuleDescriptor', function(data) {return data;});
|
.setMock('../../../ModuleDescriptor', function(data) {return data;});
|
||||||
|
|
||||||
describe('DependencyGraph', function() {
|
describe('DependencyGraph', function() {
|
||||||
|
|
|
@ -12,7 +12,7 @@ var ModuleDescriptor = require('../../ModuleDescriptor');
|
||||||
var Promise = require('bluebird');
|
var Promise = require('bluebird');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var docblock = require('./docblock');
|
var docblock = require('./docblock');
|
||||||
var requirePattern = require('../requirePattern');
|
var replacePatterns = require('../replacePatterns');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var isAbsolutePath = require('absolute-path');
|
var isAbsolutePath = require('absolute-path');
|
||||||
var debug = require('debug')('DependecyGraph');
|
var debug = require('debug')('DependecyGraph');
|
||||||
|
@ -609,7 +609,11 @@ function extractRequires(code) {
|
||||||
code
|
code
|
||||||
.replace(blockCommentRe, '')
|
.replace(blockCommentRe, '')
|
||||||
.replace(lineCommentRe, '')
|
.replace(lineCommentRe, '')
|
||||||
.replace(requirePattern, function(match, _, dep) {
|
.replace(replacePatterns.IMPORT_RE, function(match, pre, quot, dep, post) {
|
||||||
|
deps.push(dep);
|
||||||
|
return match;
|
||||||
|
})
|
||||||
|
.replace(replacePatterns.REQUIRE_RE, function(match, pre, quot, dep, post) {
|
||||||
deps.push(dep);
|
deps.push(dep);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
jest.dontMock('../')
|
jest.dontMock('../')
|
||||||
.dontMock('q')
|
.dontMock('q')
|
||||||
.dontMock('../requirePattern')
|
.dontMock('../replacePatterns')
|
||||||
.setMock('../../ModuleDescriptor', function(data) {return data;});
|
.setMock('../../ModuleDescriptor', function(data) {return data;});
|
||||||
|
|
||||||
var Promise = require('bluebird');
|
var Promise = require('bluebird');
|
||||||
|
@ -228,13 +228,148 @@ describe('HasteDependencyResolver', function() {
|
||||||
|
|
||||||
var depGraph = depResolver._depGraph;
|
var depGraph = depResolver._depGraph;
|
||||||
var dependencies = ['x', 'y', 'z', 'a', 'b'];
|
var dependencies = ['x', 'y', 'z', 'a', 'b'];
|
||||||
|
|
||||||
|
/*eslint-disable */
|
||||||
var code = [
|
var code = [
|
||||||
|
"import'x';",
|
||||||
|
"import 'x';",
|
||||||
|
"import 'x' ;",
|
||||||
|
"import Default 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 as Bar} from 'x';",
|
||||||
|
"import { Foo as Bar } from 'x';",
|
||||||
|
"import { Foo as Bar, } from 'x';",
|
||||||
|
"import { Foo, Bar } from 'x';",
|
||||||
|
"import { Foo, Bar, } from 'x';",
|
||||||
|
"import { Foo as Bar, Baz } from 'x';",
|
||||||
|
"import { Foo as Bar, Baz, } from 'x';",
|
||||||
|
"import { Foo, Bar as Baz } from 'x';",
|
||||||
|
"import { Foo, Bar as Baz, } from 'x';",
|
||||||
|
"import { Foo as Bar, Baz as Qux } from 'x';",
|
||||||
|
"import { Foo as Bar, Baz as Qux, } from 'x';",
|
||||||
|
"import { Foo, Bar, Baz } from 'x';",
|
||||||
|
"import { Foo, Bar, Baz, } from 'x';",
|
||||||
|
"import { Foo as Bar, Baz, Qux } from 'x';",
|
||||||
|
"import { Foo as Bar, Baz, Qux, } from 'x';",
|
||||||
|
"import { Foo, Bar as Baz, Qux } from 'x';",
|
||||||
|
"import { Foo, Bar as Baz, Qux, } from 'x';",
|
||||||
|
"import { Foo, Bar, Baz as Qux } from 'x';",
|
||||||
|
"import { Foo, Bar, Baz as Qux, } from 'x';",
|
||||||
|
"import { Foo as Bar, Baz as Qux, Norf } from 'x';",
|
||||||
|
"import { Foo as Bar, Baz as Qux, Norf, } from 'x';",
|
||||||
|
"import { Foo as Bar, Baz, Qux as Norf } from 'x';",
|
||||||
|
"import { Foo as Bar, Baz, Qux as Norf, } from 'x';",
|
||||||
|
"import { Foo, Bar as Baz, Qux as Norf } from 'x';",
|
||||||
|
"import { Foo, Bar as Baz, Qux as Norf, } from 'x';",
|
||||||
|
"import { Foo as Bar, Baz as Qux, Norf as Enuf } from 'x';",
|
||||||
|
"import { Foo as Bar, Baz as Qux, Norf as Enuf, } from 'x';",
|
||||||
|
"import Default, * as All from 'x';",
|
||||||
|
"import Default, { } from 'x';",
|
||||||
|
"import Default, { Foo } from 'x';",
|
||||||
|
"import Default, { Foo, } from 'x';",
|
||||||
|
"import Default, { Foo as Bar } from 'x';",
|
||||||
|
"import Default, { Foo as Bar, } from 'x';",
|
||||||
|
"import Default, { Foo, Bar } from 'x';",
|
||||||
|
"import Default, { Foo, Bar, } from 'x';",
|
||||||
|
"import Default, { Foo as Bar, Baz } from 'x';",
|
||||||
|
"import Default, { Foo as Bar, Baz, } from 'x';",
|
||||||
|
"import Default, { Foo, Bar as Baz } from 'x';",
|
||||||
|
"import Default, { Foo, Bar as Baz, } from 'x';",
|
||||||
|
"import Default, { Foo as Bar, Baz as Qux } from 'x';",
|
||||||
|
"import Default, { Foo as Bar, Baz as Qux, } from 'x';",
|
||||||
|
"import Default, { Foo, Bar, Baz } from 'x';",
|
||||||
|
"import Default, { Foo, Bar, Baz, } from 'x';",
|
||||||
|
"import Default, { Foo as Bar, Baz, Qux } from 'x';",
|
||||||
|
"import Default, { Foo as Bar, Baz, Qux, } from 'x';",
|
||||||
|
"import Default, { Foo, Bar as Baz, Qux } from 'x';",
|
||||||
|
"import Default, { Foo, Bar as Baz, Qux, } from 'x';",
|
||||||
|
"import Default, { Foo, Bar, Baz as Qux } from 'x';",
|
||||||
|
"import Default, { Foo, Bar, Baz as Qux, } from 'x';",
|
||||||
|
"import Default, { Foo as Bar, Baz as Qux, Norf } from 'x';",
|
||||||
|
"import Default, { Foo as Bar, Baz as Qux, Norf, } from 'x';",
|
||||||
|
"import Default, { Foo as Bar, Baz, Qux as Norf } from 'x';",
|
||||||
|
"import Default, { Foo as Bar, Baz, Qux as Norf, } from 'x';",
|
||||||
|
"import Default, { Foo, Bar as Baz, Qux as Norf } from 'x';",
|
||||||
|
"import Default, { Foo, Bar as Baz, Qux as Norf, } from 'x';",
|
||||||
|
"import Default, { Foo as Bar, Baz as Qux, Norf as NoMore } from 'x';",
|
||||||
|
"import Default, { Foo as Bar, Baz as Qux, Norf as NoMore, } from 'x';",
|
||||||
|
"import Default , { } from 'x';",
|
||||||
|
'import "x";',
|
||||||
|
'import Default from "x";',
|
||||||
|
'import * as All from "x";',
|
||||||
|
'import { } from "x";',
|
||||||
|
'import { Foo } from "x";',
|
||||||
|
'import { Foo, } from "x";',
|
||||||
|
'import { Foo as Bar } from "x";',
|
||||||
|
'import { Foo as Bar, } from "x";',
|
||||||
|
'import { Foo, Bar } from "x";',
|
||||||
|
'import { Foo, Bar, } from "x";',
|
||||||
|
'import { Foo as Bar, Baz } from "x";',
|
||||||
|
'import { Foo as Bar, Baz, } from "x";',
|
||||||
|
'import { Foo, Bar as Baz } from "x";',
|
||||||
|
'import { Foo, Bar as Baz, } from "x";',
|
||||||
|
'import { Foo as Bar, Baz as Qux } from "x";',
|
||||||
|
'import { Foo as Bar, Baz as Qux, } from "x";',
|
||||||
|
'import { Foo, Bar, Baz } from "x";',
|
||||||
|
'import { Foo, Bar, Baz, } from "x";',
|
||||||
|
'import { Foo as Bar, Baz, Qux } from "x";',
|
||||||
|
'import { Foo as Bar, Baz, Qux, } from "x";',
|
||||||
|
'import { Foo, Bar as Baz, Qux } from "x";',
|
||||||
|
'import { Foo, Bar as Baz, Qux, } from "x";',
|
||||||
|
'import { Foo, Bar, Baz as Qux } from "x";',
|
||||||
|
'import { Foo, Bar, Baz as Qux, } from "x";',
|
||||||
|
'import { Foo as Bar, Baz as Qux, Norf } from "x";',
|
||||||
|
'import { Foo as Bar, Baz as Qux, Norf, } from "x";',
|
||||||
|
'import { Foo as Bar, Baz, Qux as Norf } from "x";',
|
||||||
|
'import { Foo as Bar, Baz, Qux as Norf, } from "x";',
|
||||||
|
'import { Foo, Bar as Baz, Qux as Norf } from "x";',
|
||||||
|
'import { Foo, Bar as Baz, Qux as Norf, } from "x";',
|
||||||
|
'import { Foo as Bar, Baz as Qux, Norf as NoMore } from "x";',
|
||||||
|
'import { Foo as Bar, Baz as Qux, Norf as NoMore, } from "x";',
|
||||||
|
'import Default, * as All from "x";',
|
||||||
|
'import Default, { } from "x";',
|
||||||
|
'import Default, { Foo } from "x";',
|
||||||
|
'import Default, { Foo, } from "x";',
|
||||||
|
'import Default, { Foo as Bar } from "x";',
|
||||||
|
'import Default, { Foo as Bar, } from "x";',
|
||||||
|
'import Default, { Foo, Bar } from "x";',
|
||||||
|
'import Default, { Foo, Bar, } from "x";',
|
||||||
|
'import Default, { Foo as Bar, Baz } from "x";',
|
||||||
|
'import Default, { Foo as Bar, Baz, } from "x";',
|
||||||
|
'import Default, { Foo, Bar as Baz } from "x";',
|
||||||
|
'import Default, { Foo, Bar as Baz, } from "x";',
|
||||||
|
'import Default, { Foo as Bar, Baz as Qux } from "x";',
|
||||||
|
'import Default, { Foo as Bar, Baz as Qux, } from "x";',
|
||||||
|
'import Default, { Foo, Bar, Baz } from "x";',
|
||||||
|
'import Default, { Foo, Bar, Baz, } from "x";',
|
||||||
|
'import Default, { Foo as Bar, Baz, Qux } from "x";',
|
||||||
|
'import Default, { Foo as Bar, Baz, Qux, } from "x";',
|
||||||
|
'import Default, { Foo, Bar as Baz, Qux } from "x";',
|
||||||
|
'import Default, { Foo, Bar as Baz, Qux, } from "x";',
|
||||||
|
'import Default, { Foo, Bar, Baz as Qux } from "x";',
|
||||||
|
'import Default, { Foo, Bar, Baz as Qux, } from "x";',
|
||||||
|
'import Default, { Foo as Bar, Baz as Qux, Norf } from "x";',
|
||||||
|
'import Default, { Foo as Bar, Baz as Qux, Norf, } from "x";',
|
||||||
|
'import Default, { Foo as Bar, Baz, Qux as Norf } from "x";',
|
||||||
|
'import Default, { Foo as Bar, Baz, Qux as Norf, } from "x";',
|
||||||
|
'import Default, { Foo, Bar as Baz, Qux as Norf } from "x";',
|
||||||
|
'import Default, { Foo, Bar as Baz, Qux as Norf, } from "x";',
|
||||||
|
'import Default, { Foo as Bar, Baz as Qux, Norf as Enuf } from "x";',
|
||||||
|
'import Default, { Foo as Bar, Baz as Qux, Norf as Enuf, } from "x";',
|
||||||
|
'import Default from "y";',
|
||||||
|
'import * as All from \'z\';',
|
||||||
'require("x")',
|
'require("x")',
|
||||||
'require("y")',
|
'require("y")',
|
||||||
'require( "z" )',
|
'require( \'z\' )',
|
||||||
'require( "a")',
|
'require( "a")',
|
||||||
'require("b" )',
|
'require("b" )',
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
/*eslint-disable */
|
||||||
|
|
||||||
depGraph.resolveDependency.mockImpl(function(fromModule, toModuleName) {
|
depGraph.resolveDependency.mockImpl(function(fromModule, toModuleName) {
|
||||||
if (toModuleName === 'x') {
|
if (toModuleName === 'x') {
|
||||||
|
@ -242,7 +377,7 @@ describe('HasteDependencyResolver', function() {
|
||||||
id: 'changed'
|
id: 'changed'
|
||||||
};
|
};
|
||||||
} else if (toModuleName === 'y') {
|
} else if (toModuleName === 'y') {
|
||||||
return { id: 'y' };
|
return { id: 'Y' };
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
@ -254,13 +389,145 @@ describe('HasteDependencyResolver', function() {
|
||||||
}, code);
|
}, code);
|
||||||
|
|
||||||
expect(processedCode).toEqual([
|
expect(processedCode).toEqual([
|
||||||
'__d(\'test module\',["changed","y"],function(global,' +
|
'__d(\'test module\',["changed","Y"],function(global,' +
|
||||||
' require, requireDynamic, requireLazy, module, exports) {' +
|
' require, requireDynamic, requireLazy, module, exports) { ' +
|
||||||
' require(\'changed\')',
|
"import'x';",
|
||||||
'require(\'y\')',
|
"import 'changed';",
|
||||||
'require("z")',
|
"import 'changed' ;",
|
||||||
'require("a")',
|
"import Default from 'changed';",
|
||||||
'require("b")});',
|
"import * as All from 'changed';",
|
||||||
|
"import {} from 'changed';",
|
||||||
|
"import { } from 'changed';",
|
||||||
|
"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\';',
|
||||||
|
'require("changed")',
|
||||||
|
'require("Y")',
|
||||||
|
'require( \'z\' )',
|
||||||
|
'require( "a")',
|
||||||
|
'require("b" )});',
|
||||||
].join('\n'));
|
].join('\n'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var DependencyGraph = require('./DependencyGraph');
|
var DependencyGraph = require('./DependencyGraph');
|
||||||
var requirePattern = require('./requirePattern');
|
var replacePatterns = require('./replacePatterns');
|
||||||
var ModuleDescriptor = require('../ModuleDescriptor');
|
var ModuleDescriptor = require('../ModuleDescriptor');
|
||||||
var declareOpts = require('../../lib/declareOpts');
|
var declareOpts = require('../../lib/declareOpts');
|
||||||
|
|
||||||
|
@ -144,20 +144,20 @@ HasteDependencyResolver.prototype.wrapModule = function(module, code) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var relativizedCode =
|
var relativizeCode = function(codeMatch, pre, quot, depName, post) {
|
||||||
code.replace(requirePattern, function(codeMatch, _, depName) {
|
var depId = resolvedDeps[depName];
|
||||||
var depId = resolvedDeps[depName];
|
if (depId) {
|
||||||
if (depId != null) {
|
return pre + quot + depId + post;
|
||||||
return 'require(\'' + depId + '\')';
|
} else {
|
||||||
} else {
|
return codeMatch;
|
||||||
return codeMatch.replace(/\s+/g, '');
|
}
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
|
||||||
return DEFINE_MODULE_CODE.replace(DEFINE_MODULE_REPLACE_RE, function(key) {
|
return DEFINE_MODULE_CODE.replace(DEFINE_MODULE_REPLACE_RE, function(key) {
|
||||||
return {
|
return {
|
||||||
'_moduleName_': module.id,
|
'_moduleName_': module.id,
|
||||||
'_code_': relativizedCode,
|
'_code_': code.replace(replacePatterns.IMPORT_RE, relativizeCode)
|
||||||
|
.replace(replacePatterns.REQUIRE_RE, relativizeCode),
|
||||||
'_deps_': JSON.stringify(resolvedDepsArr),
|
'_deps_': JSON.stringify(resolvedDepsArr),
|
||||||
}[key];
|
}[key];
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,6 +9,5 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var REQUIRE_RE = /\brequire\s*?\(\s*?([\'"])([^"\']+)\1\s*?\)/g;
|
exports.IMPORT_RE = /(\bimport\s+?(?:.+\s+?from\s+?)?)(['"])([^'"]+)(\2)/g;
|
||||||
|
exports.REQUIRE_RE = /(\brequire\s*?\(\s*?)(['"])([^'"]+)(\2\s*?\))/g;
|
||||||
module.exports = REQUIRE_RE;
|
|
Loading…
Reference in New Issue