diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/imports.js | 123 | ||||
-rw-r--r-- | test/mocha/imports.js | 28 |
2 files changed, 151 insertions, 0 deletions
diff --git a/test/compress/imports.js b/test/compress/imports.js new file mode 100644 index 00000000..cdc239cd --- /dev/null +++ b/test/compress/imports.js @@ -0,0 +1,123 @@ +nought: { + input: { + import "foo"; + } + expect_exact: 'import"foo";' +} + +default_only: { + input: { + import foo from "bar"; + } + expect_exact: 'import foo from"bar";' +} + +all_only: { + input: { + import * as foo from "bar"; + } + expect_exact: 'import*as foo from"bar";' +} + +keys_only: { + input: { + import { as as foo, bar, delete as baz } from "moo"; + } + expect_exact: 'import{as as foo,bar as bar,delete as baz}from"moo";' +} + +default_all: { + input: { + import foo, * as bar from "baz"; + } + expect_exact: 'import foo,*as bar from"baz";' +} + +default_keys: { + input: { + import foo, { bar } from "baz"; + } + expect_exact: 'import foo,{bar as bar}from"baz";' +} + +dynamic: { + input: { + (async a => await import(a))("foo").then(bar); + } + expect_exact: '(async a=>await import(a))("foo").then(bar);' +} + +import_meta: { + input: { + console.log(import.meta, import.meta.url); + } + expect_exact: "console.log(import.meta,import.meta.url);" +} + +same_quotes: { + beautify = { + beautify: true, + quote_style: 3, + } + input: { + import 'foo'; + import "bar"; + } + expect_exact: [ + "import 'foo';", + "", + 'import "bar";', + ] +} + +drop_unused: { + options = { + imports: true, + toplevel: true, + unused: true, + } + input: { + import a, * as b from "foo"; + import { c, bar as d } from "baz"; + console.log(c); + } + expect: { + import "foo"; + import { c as c } from "baz"; + console.log(c); + } +} + +mangle: { + rename = false + mangle = { + toplevel: true, + } + input: { + import foo, { bar } from "baz"; + consoe.log(moo); + import * as moo from "moz"; + } + expect: { + import o, { bar as m } from "baz"; + consoe.log(r); + import * as r from "moz"; + } +} + +rename_mangle: { + rename = true + mangle = { + toplevel: true, + } + input: { + import foo, { bar } from "baz"; + consoe.log(moo); + import * as moo from "moz"; + } + expect: { + import o, { bar as m } from "baz"; + consoe.log(r); + import * as r from "moz"; + } +} diff --git a/test/mocha/imports.js b/test/mocha/imports.js new file mode 100644 index 00000000..e9b654cd --- /dev/null +++ b/test/mocha/imports.js @@ -0,0 +1,28 @@ +var assert = require("assert"); +var UglifyJS = require("../node"); + +describe("import", function() { + it("Should reject invalid `import` statement syntax", function() { + [ + "import *;", + "import A;", + "import {};", + "import `path`;", + "import from 'path';", + "import * from 'path';", + "import A as B from 'path';", + "import { A }, B from 'path';", + "import * as A, B from 'path';", + "import * as A, {} from 'path';", + "import { * as A } from 'path';", + "import { 42 as A } from 'path';", + "import { A-B as C } from 'path';", + ].forEach(function(code) { + assert.throws(function() { + UglifyJS.parse(code); + }, function(e) { + return e instanceof UglifyJS.JS_Parse_Error; + }, code); + }); + }); +}); |