Skip to content

Commit

Permalink
Merge branch 'master' into flow-rebased
Browse files Browse the repository at this point in the history
  • Loading branch information
rtsao committed Sep 15, 2020
2 parents 44c9581 + b790344 commit aea3d27
Show file tree
Hide file tree
Showing 29 changed files with 4,396 additions and 4,220 deletions.
296 changes: 156 additions & 140 deletions internal/bundler/bundler.go

Large diffs are not rendered by default.

53 changes: 37 additions & 16 deletions internal/bundler/bundler_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2594,25 +2594,45 @@ func TestTopLevelAwaitNoBundleIIFE(t *testing.T) {
func TestAssignToImport(t *testing.T) {
default_suite.expectBundled(t, bundled{
files: map[string]string{
"/entry.js": `import "./bad0.js"`,
"/entry.js": `
import "./bad0.js"
import "./bad1.js"
import "./bad2.js"
import "./bad3.js"
import "./bad4.js"
import "./bad5.js"
import "./bad6.js"
import "./bad7.js"
import "./bad8.js"
import "./bad9.js"
import "./bad10.js"
import "./good0.js"
import "./good1.js"
import "./good2.js"
import "./good3.js"
import "./good4.js"
`,
"/node_modules/foo/index.js": ``,

"/bad0.js": `import x from "foo"; x = 1; import "./bad1.js"`,
"/bad1.js": `import x from "foo"; x++; import "./bad2.js"`,
"/bad2.js": `import x from "foo"; ([x] = 1); import "./bad3.js"`,
"/bad3.js": `import x from "foo"; ({x} = 1); import "./bad4.js"`,
"/bad4.js": `import x from "foo"; ({y: x} = 1); import "./bad5.js"`,
"/bad5.js": `import {x} from "foo"; x++; import "./bad6.js"`,
"/bad6.js": `import * as x from "foo"; x++; import "./bad7.js"`,
"/bad7.js": `import * as x from "foo"; x.y = 1; import "./bad8.js"`,
"/bad8.js": `import * as x from "foo"; x[y] = 1; import "./bad9.js"`,
"/bad9.js": `import * as x from "foo"; x['y'] = 1; import "./good0.js"`,

"/good0.js": `import x from "foo"; ({y = x} = 1); import "./good1.js"`,
"/good1.js": `import x from "foo"; ({[x]: y} = 1); import "./good2.js"`,
"/good2.js": `import x from "foo"; x.y = 1; import "./good3.js"`,
"/good3.js": `import x from "foo"; x[y] = 1; import "./good4.js"`,
"/bad0.js": `import x from "foo"; x = 1`,
"/bad1.js": `import x from "foo"; x++`,
"/bad2.js": `import x from "foo"; ([x] = 1)`,
"/bad3.js": `import x from "foo"; ({x} = 1)`,
"/bad4.js": `import x from "foo"; ({y: x} = 1)`,
"/bad5.js": `import {x} from "foo"; x++`,
"/bad6.js": `import * as x from "foo"; x++`,
"/bad7.js": `import * as x from "foo"; x.y = 1`,
"/bad8.js": `import * as x from "foo"; x[y] = 1`,
"/bad9.js": `import * as x from "foo"; x['y'] = 1`,
"/bad10.js": `import * as x from "foo"; x['y z'] = 1`,

"/good0.js": `import x from "foo"; ({y = x} = 1)`,
"/good1.js": `import x from "foo"; ({[x]: y} = 1)`,
"/good2.js": `import x from "foo"; x.y = 1`,
"/good3.js": `import x from "foo"; x[y] = 1`,
"/good4.js": `import x from "foo"; x['y'] = 1`,
"/good5.js": `import x from "foo"; x['y z'] = 1`,
},
entryPaths: []string{"/entry.js"},
options: config.Options{
Expand All @@ -2621,6 +2641,7 @@ func TestAssignToImport(t *testing.T) {
},
expectedScanLog: `/bad0.js: error: Cannot assign to import "x"
/bad1.js: error: Cannot assign to import "x"
/bad10.js: error: Cannot assign to import "y z"
/bad2.js: error: Cannot assign to import "x"
/bad3.js: error: Cannot assign to import "x"
/bad4.js: error: Cannot assign to import "x"
Expand Down
44 changes: 40 additions & 4 deletions internal/bundler/bundler_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,42 @@ func TestLoaderJSONCommonJSAndES6(t *testing.T) {
})
}

func TestLoaderJSONInvalidIdentifierES6(t *testing.T) {
loader_suite.expectBundled(t, bundled{
files: map[string]string{
"/entry.js": `
import * as ns from './test.json'
import * as ns2 from './test2.json'
console.log(ns['invalid-identifier'], ns2)
`,
"/test.json": `{"invalid-identifier": true}`,
"/test2.json": `{"invalid-identifier": true}`,
},
entryPaths: []string{"/entry.js"},
options: config.Options{
Mode: config.ModeBundle,
AbsOutputFile: "/out.js",
},
})
}

func TestLoaderJSONMissingES6(t *testing.T) {
loader_suite.expectBundled(t, bundled{
files: map[string]string{
"/entry.js": `
import {missing} from './test.json'
`,
"/test.json": `{"present": true}`,
},
entryPaths: []string{"/entry.js"},
options: config.Options{
Mode: config.ModeBundle,
AbsOutputFile: "/out.js",
},
expectedCompileLog: "/entry.js: error: No matching export for import \"missing\"\n",
})
}

func TestLoaderTextCommonJSAndES6(t *testing.T) {
loader_suite.expectBundled(t, bundled{
files: map[string]string{
Expand Down Expand Up @@ -292,7 +328,7 @@ func TestLoaderFileCommonJSAndES6(t *testing.T) {
func TestLoaderJSONNoBundle(t *testing.T) {
loader_suite.expectBundled(t, bundled{
files: map[string]string{
"/test.json": `{"test": 123}`,
"/test.json": `{"test": 123, "invalid-identifier": true}`,
},
entryPaths: []string{"/test.json"},
options: config.Options{
Expand All @@ -304,7 +340,7 @@ func TestLoaderJSONNoBundle(t *testing.T) {
func TestLoaderJSONNoBundleES6(t *testing.T) {
loader_suite.expectBundled(t, bundled{
files: map[string]string{
"/test.json": `{"test": 123}`,
"/test.json": `{"test": 123, "invalid-identifier": true}`,
},
entryPaths: []string{"/test.json"},
options: config.Options{
Expand All @@ -318,7 +354,7 @@ func TestLoaderJSONNoBundleES6(t *testing.T) {
func TestLoaderJSONNoBundleCommonJS(t *testing.T) {
loader_suite.expectBundled(t, bundled{
files: map[string]string{
"/test.json": `{"test": 123}`,
"/test.json": `{"test": 123, "invalid-identifier": true}`,
},
entryPaths: []string{"/test.json"},
options: config.Options{
Expand All @@ -332,7 +368,7 @@ func TestLoaderJSONNoBundleCommonJS(t *testing.T) {
func TestLoaderJSONNoBundleIIFE(t *testing.T) {
loader_suite.expectBundled(t, bundled{
files: map[string]string{
"/test.json": `{"test": 123}`,
"/test.json": `{"test": 123, "invalid-identifier": true}`,
},
entryPaths: []string{"/test.json"},
options: config.Options{
Expand Down
28 changes: 18 additions & 10 deletions internal/bundler/bundler_lower_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,13 +876,21 @@ func TestLowerAsyncThis2016ES6(t *testing.T) {
func TestLowerAsyncES5(t *testing.T) {
lower_suite.expectBundled(t, bundled{
files: map[string]string{
"/entry.js": `import './fn-stmt'`,
"/fn-stmt.js": `async function foo() {} import './fn-expr'`,
"/fn-expr.js": `(async function() {}); import './arrow-1'`,
"/arrow-1.js": `(async () => {}); import './arrow-2'`,
"/arrow-2.js": `(async x => {}); import './export-def-1'`,
"/export-def-1.js": `export default async function foo() {} import './export-def-2'`,
"/export-def-2.js": `export default async function() {} import './obj-method'`,
"/entry.js": `
import './fn-stmt'
import './fn-expr'
import './arrow-1'
import './arrow-2'
import './export-def-1'
import './export-def-2'
import './obj-method'
`,
"/fn-stmt.js": `async function foo() {}`,
"/fn-expr.js": `(async function() {})`,
"/arrow-1.js": `(async () => {})`,
"/arrow-2.js": `(async x => {})`,
"/export-def-1.js": `export default async function foo() {}`,
"/export-def-2.js": `export default async function() {}`,
"/obj-method.js": `({async foo() {}})`,
},
entryPaths: []string{"/entry.js"},
Expand All @@ -891,14 +899,14 @@ func TestLowerAsyncES5(t *testing.T) {
UnsupportedFeatures: es(5),
AbsOutputFile: "/out.js",
},
expectedScanLog: `/fn-stmt.js: error: Transforming async functions to the configured target environment is not supported yet
/fn-expr.js: error: Transforming async functions to the configured target environment is not supported yet
/arrow-1.js: error: Transforming async functions to the configured target environment is not supported yet
expectedScanLog: `/arrow-1.js: error: Transforming async functions to the configured target environment is not supported yet
/arrow-1.js: error: Transforming arrow functions to the configured target environment is not supported yet
/arrow-2.js: error: Transforming async functions to the configured target environment is not supported yet
/arrow-2.js: error: Transforming arrow functions to the configured target environment is not supported yet
/export-def-1.js: error: Transforming async functions to the configured target environment is not supported yet
/export-def-2.js: error: Transforming async functions to the configured target environment is not supported yet
/fn-expr.js: error: Transforming async functions to the configured target environment is not supported yet
/fn-stmt.js: error: Transforming async functions to the configured target environment is not supported yet
/obj-method.js: error: Transforming async functions to the configured target environment is not supported yet
/obj-method.js: error: Transforming object literal extensions to the configured target environment is not supported yet
`,
Expand Down
Loading

0 comments on commit aea3d27

Please sign in to comment.