diff --git a/packager/react-packager/src/DependencyResolver/__tests__/HasteDependencyResolver-test.js b/packager/react-packager/src/DependencyResolver/__tests__/HasteDependencyResolver-test.js index 5231dc4a5..bb04dd438 100644 --- a/packager/react-packager/src/DependencyResolver/__tests__/HasteDependencyResolver-test.js +++ b/packager/react-packager/src/DependencyResolver/__tests__/HasteDependencyResolver-test.js @@ -218,6 +218,7 @@ describe('HasteDependencyResolver', function() { /*eslint-disable */ var code = [ + // single line import "import'x';", "import 'x';", "import 'x' ;", @@ -350,6 +351,63 @@ describe('HasteDependencyResolver', function() { 'import Default, { Foo as Bar, Baz as Qux, Norf as Enuf, } from "x";', 'import Default from "y";', 'import * as All from \'z\';', + // import with support for new lines + "import { Foo,\n Bar }\n from 'x';", + "import { \nFoo,\nBar,\n }\n from 'x';", + "import { Foo as Bar,\n Baz\n }\n from 'x';", + "import { \nFoo as Bar,\n Baz\n, }\n from 'x';", + "import { Foo,\n Bar as Baz\n }\n from 'x';", + "import { Foo,\n Bar as Baz,\n }\n from 'x';", + "import { Foo as Bar,\n Baz as Qux\n }\n from 'x';", + "import { Foo as Bar,\n Baz as Qux,\n }\n from 'x';", + "import { Foo,\n Bar,\n Baz }\n from 'x';", + "import { Foo,\n Bar,\n Baz,\n }\n from 'x';", + "import { Foo as Bar,\n Baz,\n Qux\n }\n from 'x';", + "import { Foo as Bar,\n Baz,\n Qux,\n }\n from 'x';", + "import { Foo,\n Bar as Baz,\n Qux\n }\n from 'x';", + "import { Foo,\n Bar as Baz,\n Qux,\n }\n from 'x';", + "import { Foo,\n Bar,\n Baz as Qux\n }\n from 'x';", + "import { Foo,\n Bar,\n Baz as Qux,\n }\n from 'x';", + "import { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'x';", + "import { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'x';", + "import { Foo as Bar,\n Baz,\n Qux as Norf\n }\n from 'x';", + "import { Foo as Bar,\n Baz,\n Qux as Norf,\n }\n from 'x';", + "import { Foo,\n Bar as Baz,\n Qux as Norf\n }\n from 'x';", + "import { Foo,\n Bar as Baz,\n Qux as Norf,\n }\n from 'x';", + "import { Foo as Bar,\n Baz as Qux,\n Norf as Enuf\n }\n from 'x';", + "import { Foo as Bar,\n Baz as Qux,\n Norf as Enuf,\n }\n from 'x';", + "import Default,\n * as All from 'x';", + "import Default,\n { } from 'x';", + "import Default,\n { Foo\n }\n from 'x';", + "import Default,\n { Foo,\n }\n from 'x';", + "import Default,\n { Foo as Bar\n }\n from 'x';", + "import Default,\n { Foo as Bar,\n }\n from 'x';", + "import Default,\n { Foo,\n Bar\n } from\n 'x';", + "import Default,\n { Foo,\n Bar,\n } from\n 'x';", + "import Default,\n { Foo as Bar,\n Baz\n }\n from 'x';", + "import Default,\n { Foo as Bar,\n Baz,\n }\n from 'x';", + "import Default,\n { Foo,\n Bar as Baz\n }\n from 'x';", + "import Default,\n { Foo,\n Bar as Baz,\n }\n from 'x';", + "import Default,\n { Foo as Bar,\n Baz as Qux\n }\n from 'x';", + "import Default,\n { Foo as Bar,\n Baz as Qux,\n }\n from 'x';", + "import Default,\n { Foo,\n Bar,\n Baz\n }\n from 'x';", + "import Default,\n { Foo,\n Bar,\n Baz,\n }\n from 'x';", + "import Default,\n { Foo as Bar,\n Baz,\n Qux\n }\n from 'x';", + "import Default,\n { Foo as Bar,\n Baz,\n Qux,\n }\n from 'x';", + "import Default,\n { Foo,\n Bar as Baz,\n Qux\n }\n from 'x';", + "import Default,\n { Foo,\n Bar as Baz,\n Qux,\n }\n from 'x';", + "import Default,\n { Foo,\n Bar,\n Baz as Qux\n }\n from 'x';", + "import Default,\n { Foo,\n Bar,\n Baz as Qux,\n }\n from 'x';", + "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf\n }\n from 'x';", + "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf,\n }\n from 'x';", + "import Default,\n { Foo as Bar,\n Baz,\n Qux as Norf }\n from 'x';", + "import Default,\n { Foo as Bar,\n Baz,\n Qux as Norf, }\n from 'x';", + "import Default,\n { Foo, Bar as Baz,\n Qux as Norf }\n from 'x';", + "import Default,\n { Foo, Bar as Baz,\n Qux as Norf, }\n from 'x';", + "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore\n }\n from 'x';", + "import Default,\n { Foo as Bar,\n Baz as Qux,\n Norf as NoMore,\n }\n from 'x';", + "import Default\n , { } from 'x';", + // require 'require("x")', 'require("y")', 'require( \'z\' )', @@ -381,6 +439,7 @@ describe('HasteDependencyResolver', function() { expect(processedCode).toEqual([ '__d(\'test module\',["changed","Y"],function(global, require,' + ' module, exports) { ' + + // single line import "import'x';", "import 'changed';", "import 'changed' ;", @@ -513,6 +572,63 @@ describe('HasteDependencyResolver', function() { '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';", + // require 'require("changed")', 'require("Y")', 'require( \'z\' )', diff --git a/packager/react-packager/src/DependencyResolver/replacePatterns.js b/packager/react-packager/src/DependencyResolver/replacePatterns.js index c27d7c770..ef5c42f2f 100644 --- a/packager/react-packager/src/DependencyResolver/replacePatterns.js +++ b/packager/react-packager/src/DependencyResolver/replacePatterns.js @@ -9,7 +9,7 @@ 'use strict'; -exports.IMPORT_RE = /(\bimport\s+?(?:.+\s+?from\s+?)?)(['"])([^'"]+)(\2)/g; +exports.IMPORT_RE = /(\bimport\s+(?:[^'"]+\s+from\s+)??)(['"])([^'"]+)(\2)/g; exports.REQUIRE_RE = /(\brequire\s*?\(\s*?)(['"])([^'"]+)(\2\s*?\))/g; exports.SYSTEM_IMPORT_RE = /(\bSystem\.import\s*?\(\s*?)(['"])([^'"]+)(\2\s*?\))/g;