diff --git a/packages/cli/test/fixtures/build-modules/expected/bundled-amd/index.html b/packages/cli/test/fixtures/build-modules/expected/bundled-amd/index.html index 647a14c5d..16de126f2 100644 --- a/packages/cli/test/fixtures/build-modules/expected/bundled-amd/index.html +++ b/packages/cli/test/fixtures/build-modules/expected/bundled-amd/index.html @@ -1,6 +1,6 @@ - + diff --git a/packages/cli/test/fixtures/build-modules/expected/unbundled-amd/index.html b/packages/cli/test/fixtures/build-modules/expected/unbundled-amd/index.html index 377395f10..b211a9a22 100644 --- a/packages/cli/test/fixtures/build-modules/expected/unbundled-amd/index.html +++ b/packages/cli/test/fixtures/build-modules/expected/unbundled-amd/index.html @@ -1,6 +1,6 @@ - + diff --git a/packages/esm-amd-loader/CHANGELOG.md b/packages/esm-amd-loader/CHANGELOG.md index 257ef9499..5b17b65b1 100644 --- a/packages/esm-amd-loader/CHANGELOG.md +++ b/packages/esm-amd-loader/CHANGELOG.md @@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). - +## Unreleased +* Load AMD modules with the same crossorigin attribute as + document.currentScript. ## [1.0.3] - 2018-09-18 diff --git a/packages/esm-amd-loader/src/esm-amd-loader.ts b/packages/esm-amd-loader/src/esm-amd-loader.ts index c9b8d10ef..2e27c00f8 100644 --- a/packages/esm-amd-loader/src/esm-amd-loader.ts +++ b/packages/esm-amd-loader/src/esm-amd-loader.ts @@ -130,8 +130,15 @@ interface ModuleG { readonly url: NormalizedUrl; readonly urlBase: NormalizedUrl; readonly exports: {[id: string]: {}}; - /** True if this is a top-level module. */ + /** + * True if this is a top-level module. + */ isTopLevel: boolean; + /** + * Value of the `crossorigin` attribute that will be used to load this + * module. + */ + readonly crossorigin: string; /** * Callbacks that are called exactly once, for the next time the module * progresses to a new state. @@ -188,6 +195,11 @@ function load(module: ModuleG): const script = document.createElement('script'); script.src = module.url; + // Crossorigin attribute could be the empty string - preserve this. + if (module.crossorigin !== null) { + script.setAttribute('crossorigin', module.crossorigin); + } + /** * Remove our script tags from the document after they have loaded/errored, to * reduce the number of nodes. Since the file load order is arbitrary and not @@ -277,7 +289,8 @@ function loadDeps( } // We have a dependency on a real module. - const dependency = getModule(resolveUrl(module.urlBase, depSpec)); + const dependency = + getModule(resolveUrl(module.urlBase, depSpec), module.crossorigin); args.push(dependency.exports); depModules.push(dependency); @@ -434,13 +447,22 @@ window.define = function(deps: string[], moduleBody?: OnExecutedCallback) { // by waiting a tick, and if we haven't already been defined by the "onload" // handler from case #1, then this must be case #2. const documentUrl = getDocumentUrl(); + + // Save the value of the crossorigin attribute before setTimeout while we + // can still get document.currentScript. If not set, default to 'anonymous' + // to match native + diff --git a/packages/polyserve/test/bower_components/test-modules/golden/test-suite-wct.html b/packages/polyserve/test/bower_components/test-modules/golden/test-suite-wct.html index 4ccc17f46..adc1dc5d2 100644 --- a/packages/polyserve/test/bower_components/test-modules/golden/test-suite-wct.html +++ b/packages/polyserve/test/bower_components/test-modules/golden/test-suite-wct.html @@ -22,7 +22,7 @@ - +