-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for changing the attributes key for dynamic imports (#5818)
- Loading branch information
Showing
29 changed files
with
161 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/form/samples/import-attributes/keep-dynamic-attributes-assert/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = defineTest({ | ||
description: 'keep import attributes for dynamic imports with "assert" key', | ||
expectedWarnings: ['UNRESOLVED_IMPORT'], | ||
options: { | ||
output: { | ||
importAttributesKey: 'assert' | ||
}, | ||
external: id => { | ||
if (id === 'unresolved') return null; | ||
return true; | ||
}, | ||
plugins: [ | ||
{ | ||
name: 'test', | ||
resolveDynamicImport(specifier) { | ||
if (typeof specifier === 'object') { | ||
if (specifier.type === 'TemplateLiteral') { | ||
return "'resolvedString'"; | ||
} | ||
if (specifier.type === 'BinaryExpression') { | ||
return { id: 'resolved-id', external: true }; | ||
} | ||
} else if (specifier === 'external-resolved') { | ||
return { id: 'resolved-different', external: true }; | ||
} | ||
return null; | ||
} | ||
} | ||
] | ||
} | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...ttributes/keep-dynamic-assertions/main.js → ...es/keep-dynamic-attributes-assert/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import('external', { assert: { type: 'special' } }); | ||
import(globalThis.unknown, { assert: { type: 'special' } }); | ||
import(`external-${globalThis.unknown}`, { assert: { type: 'special' } }); | ||
import(`external-${globalThis.unknown}`, { with: { type: 'special' } }); | ||
import('external' + globalThis.unknown, { assert: { type: 'special' } }); | ||
import('external-resolved', { assert: { type: 'special' } }); | ||
import('external-resolved', { with: { type: 'special' } }); | ||
import('unresolved', { assert: { type: 'special' } }); |
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
.../keep-dynamic-attributes/_expected/cjs.js → ...namic-attributes-default/_expected/cjs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
'use strict'; | ||
|
||
import('external', { assert: { type: 'special' } }); | ||
import(globalThis.unknown, { with: { type: 'special' } }); | ||
import('resolvedString', { with: { type: 'special' } }); | ||
import(globalThis.unknown, { assert: { type: 'special' } }); | ||
import('resolvedString', { assert: { type: 'special' } }); | ||
import('resolved-id', { assert: { type: 'special' } }); | ||
import('resolved-different', { assert: { type: 'special' } }); | ||
import('unresolved', { assert: { type: 'special' } }); |
4 changes: 2 additions & 2 deletions
4
...s/keep-dynamic-attributes/_expected/es.js → ...ynamic-attributes-default/_expected/es.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import('external', { assert: { type: 'special' } }); | ||
import(globalThis.unknown, { with: { type: 'special' } }); | ||
import('resolvedString', { with: { type: 'special' } }); | ||
import(globalThis.unknown, { assert: { type: 'special' } }); | ||
import('resolvedString', { assert: { type: 'special' } }); | ||
import('resolved-id', { assert: { type: 'special' } }); | ||
import('resolved-different', { assert: { type: 'special' } }); | ||
import('unresolved', { assert: { type: 'special' } }); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
test/form/samples/import-attributes/keep-dynamic-attributes-default/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import('external', { assert: { type: 'special' } }); | ||
import(globalThis.unknown, { assert: { type: 'special' } }); | ||
import(`external-${globalThis.unknown}`, { with: { type: 'special' } }); | ||
import('external' + globalThis.unknown, { assert: { type: 'special' } }); | ||
import('external-resolved', { with: { type: 'special' } }); | ||
import('unresolved', { assert: { type: 'special' } }); |
5 changes: 4 additions & 1 deletion
5
...ibutes/keep-dynamic-attributes/_config.js → ...s/keep-dynamic-attributes-with/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
test/form/samples/import-attributes/keep-dynamic-attributes-with/_expected/amd.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
define(['require'], (function (require) { 'use strict'; | ||
|
||
function _interopNamespaceDefault(e) { | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
}); | ||
} | ||
n.default = e; | ||
return Object.freeze(n); | ||
} | ||
|
||
new Promise(function (resolve, reject) { require(['external'], function (m) { resolve(/*#__PURE__*/_interopNamespaceDefault(m)); }, reject); }); | ||
(function (t) { return new Promise(function (resolve, reject) { require([t], function (m) { resolve(/*#__PURE__*/_interopNamespaceDefault(m)); }, reject); }); })(globalThis.unknown); | ||
(function (t) { return new Promise(function (resolve, reject) { require([t], function (m) { resolve(/*#__PURE__*/_interopNamespaceDefault(m)); }, reject); }); })('resolvedString'); | ||
new Promise(function (resolve, reject) { require(['resolved-id'], function (m) { resolve(/*#__PURE__*/_interopNamespaceDefault(m)); }, reject); }); | ||
new Promise(function (resolve, reject) { require(['resolved-different'], function (m) { resolve(/*#__PURE__*/_interopNamespaceDefault(m)); }, reject); }); | ||
new Promise(function (resolve, reject) { require(['unresolved'], function (m) { resolve(/*#__PURE__*/_interopNamespaceDefault(m)); }, reject); }); | ||
|
||
})); |
8 changes: 8 additions & 0 deletions
8
test/form/samples/import-attributes/keep-dynamic-attributes-with/_expected/cjs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
import('external', { with: { type: 'special' } }); | ||
import(globalThis.unknown, { with: { type: 'special' } }); | ||
import('resolvedString', { with: { type: 'special' } }); | ||
import('resolved-id', { with: { type: 'special' } }); | ||
import('resolved-different', { with: { type: 'special' } }); | ||
import('unresolved', { with: { type: 'special' } }); |
6 changes: 6 additions & 0 deletions
6
test/form/samples/import-attributes/keep-dynamic-attributes-with/_expected/es.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import('external', { with: { type: 'special' } }); | ||
import(globalThis.unknown, { with: { type: 'special' } }); | ||
import('resolvedString', { with: { type: 'special' } }); | ||
import('resolved-id', { with: { type: 'special' } }); | ||
import('resolved-different', { with: { type: 'special' } }); | ||
import('unresolved', { with: { type: 'special' } }); |
11 changes: 11 additions & 0 deletions
11
test/form/samples/import-attributes/keep-dynamic-attributes-with/_expected/iife.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
import('external'); | ||
import(globalThis.unknown); | ||
import('resolvedString'); | ||
import('resolved-id'); | ||
import('resolved-different'); | ||
import('unresolved'); | ||
|
||
})(); |
15 changes: 15 additions & 0 deletions
15
test/form/samples/import-attributes/keep-dynamic-attributes-with/_expected/system.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
System.register([], (function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: (function () { | ||
|
||
module.import('external'); | ||
module.import(globalThis.unknown); | ||
module.import('resolvedString'); | ||
module.import('resolved-id'); | ||
module.import('resolved-different'); | ||
module.import('unresolved'); | ||
|
||
}) | ||
}; | ||
})); |
13 changes: 13 additions & 0 deletions
13
test/form/samples/import-attributes/keep-dynamic-attributes-with/_expected/umd.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(function (factory) { | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
factory(); | ||
})((function () { 'use strict'; | ||
|
||
import('external'); | ||
import(globalThis.unknown); | ||
import('resolvedString'); | ||
import('resolved-id'); | ||
import('resolved-different'); | ||
import('unresolved'); | ||
|
||
})); |
6 changes: 6 additions & 0 deletions
6
test/form/samples/import-attributes/keep-dynamic-attributes-with/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import('external', { assert: { type: 'special' } }); | ||
import(globalThis.unknown, { assert: { type: 'special' } }); | ||
import(`external-${globalThis.unknown}`, { with: { type: 'special' } }); | ||
import('external' + globalThis.unknown, { assert: { type: 'special' } }); | ||
import('external-resolved', { with: { type: 'special' } }); | ||
import('unresolved', { assert: { type: 'special' } }); |
6 changes: 0 additions & 6 deletions
6
test/form/samples/import-attributes/keep-dynamic-attributes/main.js
This file was deleted.
Oops, something went wrong.