├── .gitignore ├── .travis.yml ├── README.md ├── package.json ├── polyfill.js ├── rollup.config.js ├── src ├── msg.js ├── vendor │ ├── acorn.js │ └── escodegen.browser.js ├── window │ ├── cluster.js │ ├── dom.js │ ├── eval.js │ ├── execute.js │ ├── index.js │ ├── module-tools.js │ ├── modules.js │ ├── registry.js │ ├── spawn.js │ └── utils.js └── worker │ ├── acorn.js │ ├── assignment-expression.js │ ├── call-expression.js │ ├── export-all-declaration.js │ ├── export-default-declaration.js │ ├── export-named-declaration.js │ ├── export-set.js │ ├── identifier.js │ ├── import-call-identifier.js │ ├── import-declaration.js │ ├── index.js │ ├── module-tools.js │ ├── property.js │ ├── source-maps.js │ ├── utils.js │ └── visitors.js ├── test ├── all.html ├── circular.html ├── errors.html ├── everything.html ├── export-syntax.html ├── import-dynamic.html ├── import-syntax.html ├── inline-everything.html ├── perf │ └── app │ │ ├── config.js │ │ ├── generate.js │ │ ├── package.json │ │ ├── polyfill.html │ │ ├── steal.html │ │ ├── steal.js │ │ └── systemjs.html ├── scope.html └── tests │ ├── circular │ ├── basics.js │ ├── src │ │ ├── a.js │ │ ├── b.js │ │ ├── one.js │ │ ├── three.js │ │ └── two.js │ └── threeway.js │ ├── errors │ ├── ref │ │ ├── bad.js │ │ └── index.js │ └── sloppy │ │ └── index.js │ ├── everything │ ├── bar.js │ ├── folder │ │ ├── thing.js │ │ └── yet-another.js │ ├── foo.js │ ├── index.html │ └── other.js │ ├── exports │ ├── default.js │ ├── from.js │ ├── let.js │ ├── object.js │ └── src │ │ ├── default-expr.js │ │ ├── default-fn.js │ │ ├── default-obj-alias.js │ │ ├── default-object.js │ │ ├── from-as.js │ │ ├── from-name.js │ │ ├── from-source.js │ │ ├── from-source2.js │ │ ├── from-star.js │ │ ├── let-equal.js │ │ ├── let-use-export.js │ │ ├── let-var.js │ │ └── object-as.js │ ├── import-fn │ ├── dynamic.js │ ├── multi-arg.js │ ├── spread.js │ └── src │ │ ├── bar.js │ │ ├── baz.js │ │ ├── foo.js │ │ └── qux.js │ ├── imports │ ├── default-and-member.js │ ├── default-and-star.js │ ├── default.js │ ├── member-alias.js │ ├── members.js │ ├── side-effect.js │ ├── src │ │ ├── default-and-member.js │ │ ├── default-and-star.js │ │ ├── default.js │ │ ├── members.js │ │ ├── side-effect.js │ │ └── star.js │ └── star.js │ └── scope │ ├── main.js │ ├── src │ └── foo.js │ └── var.js └── worker.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | test/perf/app/src/ 3 | test/perf/app/node_modules/ 4 | test/perf/app/jspm_packages/ 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | language: node_js 3 | node_js: 6.3 4 | before_script: 5 | - npm install -g testee 6 | script: npm test 7 | before_install: 8 | - "export DISPLAY=:99.0" 9 | - "sh -e /etc/init.d/xvfb start" 10 | addons: 11 | firefox: "49.0" 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # <script type=module> - the polyfill! 2 | 3 | An attempt to build a polyfill for [\ 26 | 27 | 28 | ``` 29 | 30 | ### Dynamic import 31 | 32 | The [stage 2 import()](https://github.com/domenic/proposal-dynamic-import) proposal allows you to dynamically import code based on runtime considerations. This is useful if you want to delay loading parts of the application for any reason (such as based on user input). 33 | 34 | This polyfill includes support for `import()`. Here's an example usage: 35 | 36 | **/pages/home.js** 37 | 38 | ```js 39 | export function page(){ 40 | let section = document.createElement('section'); 41 | section.innerHTML = ` 42 |

Home

43 | 44 |

Welcome home!

45 | `; 46 | 47 | return section; 48 | } 49 | ``` 50 | 51 | **index.html** 52 | 53 | ```html 54 |
55 | 56 | 57 | 58 | 65 | ``` 66 | 67 | In this case we are dynamically inserting DOM based on the `location.hash`, so that if the URL is `http://example.com#home` the `/pages/home.js` module is dynamically imported and inserted into `
`. 68 | 69 | ## FAQ 70 | 71 | **Why use this instead of a bundler?** 72 | 73 | Bundlers are not great for development workflows. Being able to create new `.html` pages to test out small parts of your application without creating a new build just for that, is a super powerful thing. 74 | 75 | **Should I use this in production?** 76 | 77 | No! This is primarily meant for better development workflows. Do a real build for production. 78 | 79 | **How does this compare to es-module-loader?** 80 | 81 | es-module-loader is a polyfill for the in progress [whatwg/loader](https://github.com/whatwg/loader) spec. This spec has been through several revisions going back many years and isn't likely to appear in browsers soon. 82 | 83 | This polyfill is based on the already specified ` 6 | 7 | 8 | 9 | 10 |
11 | 12 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /test/errors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Test error handling 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /test/everything.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Test everything 5 | 6 | 7 | 8 | 9 | 10 |
11 |
12 | 16 | 17 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /test/export-syntax.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Test export syntaxes 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /test/import-dynamic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Test import syntaxes 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /test/import-syntax.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Test import syntaxes 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /test/inline-everything.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Test everything 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /test/perf/app/config.js: -------------------------------------------------------------------------------- 1 | System.config({ 2 | //baseURL: "/", 3 | defaultJSExtensions: true, 4 | transpiler: "babel", 5 | babelOptions: { 6 | "optional": [ 7 | "runtime", 8 | "optimisation.modules.system" 9 | ] 10 | }, 11 | paths: { 12 | "github:*": "jspm_packages/github/*", 13 | "npm:*": "jspm_packages/npm/*" 14 | }, 15 | 16 | map: { 17 | "babel": "npm:babel-core@5.8.38", 18 | "babel-runtime": "npm:babel-runtime@5.8.38", 19 | "core-js": "npm:core-js@1.2.7", 20 | "github:jspm/nodelibs-assert@0.1.0": { 21 | "assert": "npm:assert@1.4.1" 22 | }, 23 | "github:jspm/nodelibs-buffer@0.1.0": { 24 | "buffer": "npm:buffer@3.6.0" 25 | }, 26 | "github:jspm/nodelibs-path@0.1.0": { 27 | "path-browserify": "npm:path-browserify@0.0.0" 28 | }, 29 | "github:jspm/nodelibs-process@0.1.2": { 30 | "process": "npm:process@0.11.9" 31 | }, 32 | "github:jspm/nodelibs-util@0.1.0": { 33 | "util": "npm:util@0.10.3" 34 | }, 35 | "github:jspm/nodelibs-vm@0.1.0": { 36 | "vm-browserify": "npm:vm-browserify@0.0.4" 37 | }, 38 | "npm:assert@1.4.1": { 39 | "assert": "github:jspm/nodelibs-assert@0.1.0", 40 | "buffer": "github:jspm/nodelibs-buffer@0.1.0", 41 | "process": "github:jspm/nodelibs-process@0.1.2", 42 | "util": "npm:util@0.10.3" 43 | }, 44 | "npm:babel-runtime@5.8.38": { 45 | "process": "github:jspm/nodelibs-process@0.1.2" 46 | }, 47 | "npm:buffer@3.6.0": { 48 | "base64-js": "npm:base64-js@0.0.8", 49 | "child_process": "github:jspm/nodelibs-child_process@0.1.0", 50 | "fs": "github:jspm/nodelibs-fs@0.1.2", 51 | "ieee754": "npm:ieee754@1.1.6", 52 | "isarray": "npm:isarray@1.0.0", 53 | "process": "github:jspm/nodelibs-process@0.1.2" 54 | }, 55 | "npm:core-js@1.2.7": { 56 | "fs": "github:jspm/nodelibs-fs@0.1.2", 57 | "path": "github:jspm/nodelibs-path@0.1.0", 58 | "process": "github:jspm/nodelibs-process@0.1.2", 59 | "systemjs-json": "github:systemjs/plugin-json@0.1.2" 60 | }, 61 | "npm:inherits@2.0.1": { 62 | "util": "github:jspm/nodelibs-util@0.1.0" 63 | }, 64 | "npm:path-browserify@0.0.0": { 65 | "process": "github:jspm/nodelibs-process@0.1.2" 66 | }, 67 | "npm:process@0.11.9": { 68 | "assert": "github:jspm/nodelibs-assert@0.1.0", 69 | "fs": "github:jspm/nodelibs-fs@0.1.2", 70 | "vm": "github:jspm/nodelibs-vm@0.1.0" 71 | }, 72 | "npm:util@0.10.3": { 73 | "inherits": "npm:inherits@2.0.1", 74 | "process": "github:jspm/nodelibs-process@0.1.2" 75 | }, 76 | "npm:vm-browserify@0.0.4": { 77 | "indexof": "npm:indexof@0.0.1" 78 | } 79 | } 80 | }); 81 | -------------------------------------------------------------------------------- /test/perf/app/generate.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | 4 | const max = 500; 5 | const deps = 10; 6 | const first = 30; 7 | 8 | let includeJS = process.argv[2] !== '--no-js'; 9 | 10 | let cnt = 0; 11 | 12 | let importer = function(pth){ 13 | return ` 14 | import def from './${pth}'; 15 | `; 16 | } 17 | 18 | let exporter = function(){ 19 | return ` 20 | export default function(){ 21 | }; 22 | `; 23 | } 24 | 25 | let importerExporter = function(pth){ 26 | return ` 27 | import def from './${pth}'; 28 | 29 | export default function(){ 30 | }; 31 | `; 32 | }; 33 | 34 | let mainTmpl = function(names){ 35 | return ` 36 | import './${names[0]}'; 37 | import './${names[1]}'; 38 | import './${names[2]}'; 39 | import './${names[3]}'; 40 | import './${names[4]}'; 41 | import './${names[5]}'; 42 | import './${names[6]}'; 43 | import './${names[7]}'; 44 | import './${names[8]}'; 45 | import './${names[9]}'; 46 | `; 47 | } 48 | 49 | let names = {}; 50 | function makeName(){ 51 | let name = Math.random().toString(36).substring(7); 52 | if(names[name]) { 53 | return makeName(); 54 | } 55 | names[name] = true; 56 | return name; 57 | } 58 | 59 | function makeModule(tmpl, hasChildren){ 60 | cnt++; 61 | let name = makeName(); 62 | let fn = includeJS ? name + '.js' : name; 63 | let pth = path.join(__dirname, 'src', name + '.js'); 64 | 65 | let src; 66 | if(hasChildren && cnt < max) { 67 | let nextTmpl, willHaveChildren = true; 68 | if((cnt + 10) < max) { 69 | nextTmpl = importerExporter; 70 | } else { 71 | nextTmpl = exporter; 72 | willHaveChildren = false; 73 | } 74 | 75 | let child = makeModule(nextTmpl, willHaveChildren); 76 | src = tmpl(child); 77 | } else { 78 | tmpl = exporter; 79 | src = tmpl(); 80 | } 81 | 82 | //console.log(src); 83 | fs.writeFileSync(pth, src, 'utf8'); 84 | 85 | return fn; 86 | } 87 | 88 | let mainDeps = []; 89 | 90 | for(var i = 0; i < first; i++) { 91 | let local = makeModule(importer, true); 92 | mainDeps.push(local); 93 | } 94 | 95 | let src = mainTmpl(mainDeps); 96 | let pth = path.join(__dirname, 'src', 'main.js'); 97 | fs.writeFileSync(pth, src, 'utf8'); 98 | -------------------------------------------------------------------------------- /test/perf/app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "1.0.0", 4 | "main": "src/main.js", 5 | "dependencies": { 6 | "steal": "^1.0.0-rc.0" 7 | }, 8 | "jspm": { 9 | "dependencies": {}, 10 | "devDependencies": { 11 | "babel": "npm:babel-core@^5.8.24", 12 | "babel-runtime": "npm:babel-runtime@^5.8.24", 13 | "core-js": "npm:core-js@^1.1.4" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/perf/app/polyfill.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Perf test 5 | 6 | 7 |

script-type-module test

8 | 9 |

Loading

10 |

11 | 12 | 13 | 14 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /test/perf/app/steal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Perf test 5 | 6 | 7 |

Loading

8 |

9 | 10 | 11 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /test/perf/app/systemjs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Perf test 5 | 6 | 7 |

SystemJS test

8 | 9 |

Loading

10 |

11 | 12 | 13 | 14 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /test/scope.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Test scoping 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /test/tests/circular/basics.js: -------------------------------------------------------------------------------- 1 | import { a, c as aC } from './src/a.js'; 2 | import { b, c as bC } from './src/b.js'; 3 | 4 | self.RESULT = { 5 | a: a, 6 | b: b, 7 | aC: aC, 8 | bC: bC 9 | }; 10 | -------------------------------------------------------------------------------- /test/tests/circular/src/a.js: -------------------------------------------------------------------------------- 1 | import { b } from './b.js'; 2 | 3 | export function a(){ 4 | return 'a'; 5 | }; 6 | 7 | export function c() { 8 | return b(); 9 | }; 10 | -------------------------------------------------------------------------------- /test/tests/circular/src/b.js: -------------------------------------------------------------------------------- 1 | import { a } from './a.js'; 2 | 3 | export function b(){ 4 | return 'b'; 5 | }; 6 | 7 | export function c() { 8 | return a(); 9 | }; 10 | -------------------------------------------------------------------------------- /test/tests/circular/src/one.js: -------------------------------------------------------------------------------- 1 | import { b } from './two.js'; 2 | 3 | export function a(){ 4 | return 'a'; 5 | }; 6 | 7 | export function one() { 8 | return b(); 9 | }; 10 | -------------------------------------------------------------------------------- /test/tests/circular/src/three.js: -------------------------------------------------------------------------------- 1 | import { a } from './one.js'; 2 | 3 | export function c(){ 4 | return 'c'; 5 | }; 6 | 7 | export function three(){ 8 | return a(); 9 | } 10 | -------------------------------------------------------------------------------- /test/tests/circular/src/two.js: -------------------------------------------------------------------------------- 1 | import { c } from './three.js'; 2 | 3 | export function b() { 4 | return 'b'; 5 | }; 6 | 7 | export function two() { 8 | return c(); 9 | }; 10 | -------------------------------------------------------------------------------- /test/tests/circular/threeway.js: -------------------------------------------------------------------------------- 1 | import { one } from './src/one.js'; 2 | import { two } from './src/two.js'; 3 | import { three } from './src/three.js'; 4 | 5 | self.RESULT = { 6 | one: one, 7 | two: two, 8 | three: three 9 | }; 10 | -------------------------------------------------------------------------------- /test/tests/errors/ref/bad.js: -------------------------------------------------------------------------------- 1 | function foo() { 2 | bar(); 3 | } 4 | 5 | foo(); 6 | -------------------------------------------------------------------------------- /test/tests/errors/ref/index.js: -------------------------------------------------------------------------------- 1 | import './bad.js'; 2 | -------------------------------------------------------------------------------- /test/tests/errors/sloppy/index.js: -------------------------------------------------------------------------------- 1 | someGlobal = true; 2 | -------------------------------------------------------------------------------- /test/tests/everything/bar.js: -------------------------------------------------------------------------------- 1 | import { bar } from './other.js'; 2 | 3 | function someFunction(foo = []) { 4 | // Just verifying that default args work 5 | } 6 | 7 | host2.innerHTML = 'bar' + bar(); 8 | -------------------------------------------------------------------------------- /test/tests/everything/folder/thing.js: -------------------------------------------------------------------------------- 1 | import './yet-another.js'; 2 | 3 | export default function(){ 4 | 5 | }; 6 | -------------------------------------------------------------------------------- /test/tests/everything/folder/yet-another.js: -------------------------------------------------------------------------------- 1 | let foo = 'bar'; 2 | 3 | export default foo; 4 | -------------------------------------------------------------------------------- /test/tests/everything/foo.js: -------------------------------------------------------------------------------- 1 | import { bar } from './other.js'; 2 | 3 | host.innerHTML = 'foo' + bar(); 4 | -------------------------------------------------------------------------------- /test/tests/everything/index.html: -------------------------------------------------------------------------------- 1 | Demo 2 |

Loading...

3 | 4 | 5 | -------------------------------------------------------------------------------- /test/tests/everything/other.js: -------------------------------------------------------------------------------- 1 | import thing from './folder/thing.js'; 2 | 3 | export function bar(){ 4 | return 'bar'; 5 | }; 6 | -------------------------------------------------------------------------------- /test/tests/exports/default.js: -------------------------------------------------------------------------------- 1 | import a from './src/default-fn.js'; 2 | import b from './src/default-expr.js'; 3 | import c from './src/default-obj-alias.js'; 4 | import d from './src/default-object.js'; 5 | 6 | self.RESULT = { 7 | a: a, 8 | b: b, 9 | c: c, 10 | d: d 11 | }; 12 | -------------------------------------------------------------------------------- /test/tests/exports/from.js: -------------------------------------------------------------------------------- 1 | import { a, aB } from './src/from-name.js'; 2 | import { b } from './src/from-as.js'; 3 | import * as c from './src/from-star.js'; 4 | 5 | /** 6 | * TODO: 7 | * export { a as b } from 8 | * export * from 9 | */ 10 | 11 | self.RESULT = { 12 | getA: function(){ 13 | return a; 14 | }, 15 | aB: aB, 16 | b: b, 17 | c: c 18 | }; 19 | -------------------------------------------------------------------------------- /test/tests/exports/let.js: -------------------------------------------------------------------------------- 1 | import { a } from './src/let-equal.js'; 2 | import { b } from './src/let-var.js'; 3 | import { c } from './src/let-use-export.js'; 4 | 5 | self.RESULT = { 6 | a, 7 | b, 8 | c 9 | }; 10 | -------------------------------------------------------------------------------- /test/tests/exports/object.js: -------------------------------------------------------------------------------- 1 | import { b } from './src/object-as.js'; 2 | 3 | self.RESULT = { 4 | b: b 5 | }; 6 | -------------------------------------------------------------------------------- /test/tests/exports/src/default-expr.js: -------------------------------------------------------------------------------- 1 | export default 'b'; 2 | -------------------------------------------------------------------------------- /test/tests/exports/src/default-fn.js: -------------------------------------------------------------------------------- 1 | export default function(){ 2 | return 'a'; 3 | }; 4 | -------------------------------------------------------------------------------- /test/tests/exports/src/default-obj-alias.js: -------------------------------------------------------------------------------- 1 | const c = 'c'; 2 | 3 | export { c as default }; 4 | -------------------------------------------------------------------------------- /test/tests/exports/src/default-object.js: -------------------------------------------------------------------------------- 1 | let a = 'a'; 2 | let b = 'b'; 3 | 4 | export default { 5 | a: a, 6 | b: b, 7 | c: c 8 | }; 9 | 10 | function c(){ 11 | return 'c'; 12 | } 13 | -------------------------------------------------------------------------------- /test/tests/exports/src/from-as.js: -------------------------------------------------------------------------------- 1 | export { a as b } from './from-source2.js'; 2 | -------------------------------------------------------------------------------- /test/tests/exports/src/from-name.js: -------------------------------------------------------------------------------- 1 | export { a, aB } from './from-source.js'; 2 | -------------------------------------------------------------------------------- /test/tests/exports/src/from-source.js: -------------------------------------------------------------------------------- 1 | export let a = 'a'; 2 | 3 | export function aB(){ 4 | a = 'ab'; 5 | } 6 | -------------------------------------------------------------------------------- /test/tests/exports/src/from-source2.js: -------------------------------------------------------------------------------- 1 | export let a = 'a'; 2 | -------------------------------------------------------------------------------- /test/tests/exports/src/from-star.js: -------------------------------------------------------------------------------- 1 | export * from './from-source.js'; 2 | -------------------------------------------------------------------------------- /test/tests/exports/src/let-equal.js: -------------------------------------------------------------------------------- 1 | export let a = 'a'; 2 | -------------------------------------------------------------------------------- /test/tests/exports/src/let-use-export.js: -------------------------------------------------------------------------------- 1 | export let d; 2 | 3 | d = 'c'; 4 | 5 | export function c(){ 6 | return d; 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/tests/exports/src/let-var.js: -------------------------------------------------------------------------------- 1 | export let b; 2 | 3 | b = 'b'; 4 | -------------------------------------------------------------------------------- /test/tests/exports/src/object-as.js: -------------------------------------------------------------------------------- 1 | let a = 'a'; 2 | 3 | export { a as b }; 4 | -------------------------------------------------------------------------------- /test/tests/import-fn/dynamic.js: -------------------------------------------------------------------------------- 1 | import foo from './src/foo.js'; 2 | 3 | let barPromise = import('./src/bar.js'); 4 | let quxPromise = import('./src/qux.js').then(function(qux){ 5 | return qux; 6 | }); 7 | let pageUrl = new URL('./tests/import-fn/src/baz.js', document.baseURI); 8 | let bazPromise = import(pageUrl); 9 | 10 | self.RESULT = { 11 | foo: foo, 12 | bar: barPromise, 13 | baz: bazPromise, 14 | qux: quxPromise 15 | }; 16 | -------------------------------------------------------------------------------- /test/tests/import-fn/multi-arg.js: -------------------------------------------------------------------------------- 1 | // This should be a SyntaxError according to 2 | // https://github.com/domenic/proposal-dynamic-import/issues/15 3 | 4 | let barPromise = import('./src/bar.js', { something: 'else' }); 5 | 6 | self.RESULT = { 7 | bar: barPromise 8 | }; 9 | -------------------------------------------------------------------------------- /test/tests/import-fn/spread.js: -------------------------------------------------------------------------------- 1 | // This should be a SyntaxError according to 2 | // https://github.com/domenic/proposal-dynamic-import/issues/15 3 | 4 | let barPromise = import(...['./src/bar.js']); 5 | 6 | self.RESULT = { 7 | bar: barPromise 8 | }; 9 | -------------------------------------------------------------------------------- /test/tests/import-fn/src/bar.js: -------------------------------------------------------------------------------- 1 | export default 'bar'; 2 | -------------------------------------------------------------------------------- /test/tests/import-fn/src/baz.js: -------------------------------------------------------------------------------- 1 | export default 'baz'; 2 | -------------------------------------------------------------------------------- /test/tests/import-fn/src/foo.js: -------------------------------------------------------------------------------- 1 | export default 'foo'; 2 | -------------------------------------------------------------------------------- /test/tests/import-fn/src/qux.js: -------------------------------------------------------------------------------- 1 | export default 'qux'; 2 | -------------------------------------------------------------------------------- /test/tests/imports/default-and-member.js: -------------------------------------------------------------------------------- 1 | import a, {b} from './src/default-and-member.js'; 2 | 3 | self.RESULT = { 4 | a: a, 5 | b 6 | }; 7 | -------------------------------------------------------------------------------- /test/tests/imports/default-and-star.js: -------------------------------------------------------------------------------- 1 | import a, * as star from './src/default-and-star.js'; 2 | 3 | self.RESULT = { 4 | a: a, 5 | b: star.b, 6 | c: star.c 7 | }; 8 | -------------------------------------------------------------------------------- /test/tests/imports/default.js: -------------------------------------------------------------------------------- 1 | import foo from './src/default.js'; 2 | 3 | self.RESULT = { 4 | foo: foo() 5 | }; 6 | -------------------------------------------------------------------------------- /test/tests/imports/member-alias.js: -------------------------------------------------------------------------------- 1 | import {a as b} from './src/members.js'; 2 | 3 | self.RESULT = { 4 | a: b 5 | }; 6 | -------------------------------------------------------------------------------- /test/tests/imports/members.js: -------------------------------------------------------------------------------- 1 | import {a, b} from './src/members.js'; 2 | 3 | self.RESULT = { 4 | a: a, 5 | b: b 6 | }; 7 | -------------------------------------------------------------------------------- /test/tests/imports/side-effect.js: -------------------------------------------------------------------------------- 1 | import './src/side-effect.js'; 2 | -------------------------------------------------------------------------------- /test/tests/imports/src/default-and-member.js: -------------------------------------------------------------------------------- 1 | export default a = 'a'; 2 | export let b = 'b'; 3 | -------------------------------------------------------------------------------- /test/tests/imports/src/default-and-star.js: -------------------------------------------------------------------------------- 1 | export default a = 'a'; 2 | export let b = 'b'; 3 | export let c = 'c'; 4 | -------------------------------------------------------------------------------- /test/tests/imports/src/default.js: -------------------------------------------------------------------------------- 1 | export default function(){ 2 | return 'bar'; 3 | }; 4 | -------------------------------------------------------------------------------- /test/tests/imports/src/members.js: -------------------------------------------------------------------------------- 1 | export let a = 'a'; 2 | export let b = 'b'; 3 | -------------------------------------------------------------------------------- /test/tests/imports/src/side-effect.js: -------------------------------------------------------------------------------- 1 | self.RESULT = 'it worked'; 2 | -------------------------------------------------------------------------------- /test/tests/imports/src/star.js: -------------------------------------------------------------------------------- 1 | export function foo(){ 2 | return 'bar'; 3 | }; 4 | 5 | export let bar = 17; 6 | -------------------------------------------------------------------------------- /test/tests/imports/star.js: -------------------------------------------------------------------------------- 1 | import * as star from './src/star.js'; 2 | 3 | if(self.RESULT) { 4 | throw new Error('This module has already loaded'); 5 | } 6 | 7 | self.RESULT = { 8 | foo: star.foo(), 9 | bar: star.bar 10 | }; 11 | -------------------------------------------------------------------------------- /test/tests/scope/main.js: -------------------------------------------------------------------------------- 1 | import {foo} from './src/foo.js'; 2 | 3 | let result = self.RESULT = {}; 4 | 5 | result.one = foo(); 6 | 7 | function bar(foo){ 8 | result.two = foo(); 9 | } 10 | 11 | bar(function(){ 12 | return 'bar'; 13 | }); 14 | 15 | let qux = (foo) => { 16 | result.three = foo(); 17 | }; 18 | 19 | qux(function(){ 20 | return 'qux'; 21 | }); 22 | 23 | let baz = function(foo){ 24 | result.four = foo(); 25 | }; 26 | 27 | baz(() => 'baz'); 28 | 29 | class Thing { 30 | constructor() { 31 | result.five = foo(); 32 | } 33 | 34 | another(foo) { 35 | result.six = foo(); 36 | } 37 | } 38 | 39 | let obj = new Thing(); 40 | obj.another(() => 'quux'); 41 | -------------------------------------------------------------------------------- /test/tests/scope/src/foo.js: -------------------------------------------------------------------------------- 1 | export function foo(){ 2 | return 'foo'; 3 | }; 4 | -------------------------------------------------------------------------------- /test/tests/scope/var.js: -------------------------------------------------------------------------------- 1 | import {foo} from './src/foo.js'; 2 | 3 | let result = self.RESULT = {}; 4 | 5 | result.one = foo(); 6 | 7 | function bar(){ 8 | var foo = () => 'bar'; 9 | result.two = foo(); 10 | } 11 | bar(); 12 | 13 | function baz(){ 14 | let foo = function() { return 'baz' }; 15 | result.three = foo(); 16 | } 17 | baz(); 18 | 19 | function qux() { 20 | const foo = () => 'qux'; 21 | result.four = foo(); 22 | } 23 | qux(); 24 | --------------------------------------------------------------------------------