@@ -8894,3 +8894,204 @@ func TestObjectLiteralProtoSetterEdgeCasesMinifySyntax(t *testing.T) {
88948894 },
88958895 })
88968896}
8897+
8898+ func TestForbidStringImportNamesNoBundle (t * testing.T ) {
8899+ default_suite .expectBundled (t , bundled {
8900+ files : map [string ]string {
8901+ "/entry.js" : `
8902+ import { "an import" as anImport } from "./foo"
8903+ export { "another import" as "an export" } from "./foo"
8904+ anImport()
8905+ ` ,
8906+ },
8907+ entryPaths : []string {"/entry.js" },
8908+ options : config.Options {
8909+ Mode : config .ModePassThrough ,
8910+ AbsOutputFile : "/out.js" ,
8911+ UnsupportedJSFeatures : compat .ArbitraryModuleNamespaceNames ,
8912+ },
8913+ expectedCompileLog : `entry.js: ERROR: Using the string "an import" as an import name is not supported in the configured target environment
8914+ entry.js: ERROR: Using the string "another import" as an import name is not supported in the configured target environment
8915+ entry.js: ERROR: Using the string "an export" as an export name is not supported in the configured target environment
8916+ ` ,
8917+ })
8918+ }
8919+
8920+ func TestForbidStringExportNamesNoBundle (t * testing.T ) {
8921+ default_suite .expectBundled (t , bundled {
8922+ files : map [string ]string {
8923+ "/entry.js" : `
8924+ let ok = true
8925+ export { ok as "ok", ok as "not ok" }
8926+ export { "same name" } from "./foo"
8927+ export { "name 1" as "name 2" } from "./foo"
8928+ export * as "name space" from "./foo"
8929+ ` ,
8930+ },
8931+ entryPaths : []string {"/entry.js" },
8932+ options : config.Options {
8933+ Mode : config .ModePassThrough ,
8934+ AbsOutputFile : "/out.js" ,
8935+ UnsupportedJSFeatures : compat .ArbitraryModuleNamespaceNames ,
8936+ },
8937+ expectedCompileLog : `entry.js: ERROR: Using the string "not ok" as an export name is not supported in the configured target environment
8938+ entry.js: ERROR: Using the string "same name" as an export name is not supported in the configured target environment
8939+ entry.js: ERROR: Using the string "name 1" as an import name is not supported in the configured target environment
8940+ entry.js: ERROR: Using the string "name 2" as an export name is not supported in the configured target environment
8941+ entry.js: ERROR: Using the string "name space" as an export name is not supported in the configured target environment
8942+ ` ,
8943+ })
8944+ }
8945+
8946+ func TestForbidStringImportNamesBundle (t * testing.T ) {
8947+ default_suite .expectBundled (t , bundled {
8948+ files : map [string ]string {
8949+ "/entry.js" : `
8950+ import { "nest ed" as nested } from "./nested.js"
8951+ export { nested }
8952+ ` ,
8953+ "/nested.js" : `
8954+ import { "some import" as nested } from "external"
8955+ export { nested as "nest ed" }
8956+ ` ,
8957+ },
8958+ entryPaths : []string {"/entry.js" },
8959+ options : config.Options {
8960+ Mode : config .ModeBundle ,
8961+ AbsOutputFile : "/out.js" ,
8962+ UnsupportedJSFeatures : compat .ArbitraryModuleNamespaceNames ,
8963+ ExternalSettings : config.ExternalSettings {
8964+ PreResolve : config.ExternalMatchers {Exact : map [string ]bool {
8965+ "external" : true ,
8966+ }},
8967+ },
8968+ },
8969+ expectedCompileLog : `nested.js: ERROR: Using the string "some import" as an import name is not supported in the configured target environment
8970+ ` ,
8971+ })
8972+ }
8973+
8974+ func TestForbidStringExportNamesBundle (t * testing.T ) {
8975+ default_suite .expectBundled (t , bundled {
8976+ files : map [string ]string {
8977+ "/entry.js" : `
8978+ import { "o.k." as ok } from "./internal.js"
8979+ export { ok as "ok", ok as "not ok" }
8980+ export * from "./nested.js"
8981+ export * as "name space" from "./nested.js"
8982+ ` ,
8983+ "/internal.js" : `
8984+ let ok = true
8985+ export { ok as "o.k." }
8986+ ` ,
8987+ "/nested.js" : `
8988+ export * from "./very-nested.js"
8989+ let nested = 1
8990+ export { nested as "nested name" }
8991+ ` ,
8992+ "/very-nested.js" : `
8993+ let nested = 2
8994+ export { nested as "very nested name" }
8995+ ` ,
8996+ },
8997+ entryPaths : []string {"/entry.js" },
8998+ options : config.Options {
8999+ Mode : config .ModeBundle ,
9000+ AbsOutputFile : "/out.js" ,
9001+ UnsupportedJSFeatures : compat .ArbitraryModuleNamespaceNames ,
9002+ },
9003+ expectedCompileLog : `entry.js: ERROR: Using the string "not ok" as an export name is not supported in the configured target environment
9004+ entry.js: ERROR: Using the string "name space" as an export name is not supported in the configured target environment
9005+ nested.js: ERROR: Using the string "nested name" as an export name is not supported in the configured target environment
9006+ very-nested.js: ERROR: Using the string "very nested name" as an export name is not supported in the configured target environment
9007+ ` ,
9008+ })
9009+ }
9010+
9011+ func TestInjectWithStringExportNameNoBundle (t * testing.T ) {
9012+ default_suite .expectBundled (t , bundled {
9013+ files : map [string ]string {
9014+ "/entry.js" : `
9015+ console.log(test)
9016+ ` ,
9017+ "/inject.js" : `
9018+ const old = console.log
9019+ const fn = (...args) => old.apply(console, ['log:'].concat(args))
9020+ export { fn as "console.log" }
9021+ ` ,
9022+ },
9023+ entryPaths : []string {"/entry.js" },
9024+ options : config.Options {
9025+ Mode : config .ModePassThrough ,
9026+ AbsOutputFile : "/out.js" ,
9027+ InjectPaths : []string {"/inject.js" },
9028+ UnsupportedJSFeatures : compat .ArbitraryModuleNamespaceNames ,
9029+ },
9030+ })
9031+ }
9032+
9033+ func TestInjectWithStringExportNameBundle (t * testing.T ) {
9034+ default_suite .expectBundled (t , bundled {
9035+ files : map [string ]string {
9036+ "/entry.js" : `
9037+ console.log(test)
9038+ console.info(test)
9039+ console.warn(test)
9040+ ` ,
9041+ "/inject.js" : `
9042+ const old = console.log
9043+ const fn = (...args) => old.apply(console, ['log:'].concat(args))
9044+ export { fn as "console.log" }
9045+ export { "console.log" as "console.info" } from "./inject.js"
9046+ import { "console.info" as info } from "./inject.js"
9047+ export { info as "console.warn" }
9048+ ` ,
9049+ },
9050+ entryPaths : []string {"/entry.js" },
9051+ options : config.Options {
9052+ Mode : config .ModeBundle ,
9053+ AbsOutputFile : "/out.js" ,
9054+ InjectPaths : []string {"/inject.js" },
9055+ UnsupportedJSFeatures : compat .ArbitraryModuleNamespaceNames ,
9056+ },
9057+ })
9058+ }
9059+
9060+ func TestStringExportNamesCommonJS (t * testing.T ) {
9061+ default_suite .expectBundled (t , bundled {
9062+ files : map [string ]string {
9063+ "/entry.js" : `
9064+ import { "some import" as someImport } from "./foo"
9065+ export { someImport as "some export" }
9066+ export * as "all the stuff" from "./foo"
9067+ ` ,
9068+ },
9069+ entryPaths : []string {"/entry.js" },
9070+ options : config.Options {
9071+ Mode : config .ModeConvertFormat ,
9072+ AbsOutputFile : "/out.js" ,
9073+ OutputFormat : config .FormatCommonJS ,
9074+ UnsupportedJSFeatures : compat .ArbitraryModuleNamespaceNames ,
9075+ },
9076+ })
9077+ }
9078+
9079+ func TestStringExportNamesIIFE (t * testing.T ) {
9080+ default_suite .expectBundled (t , bundled {
9081+ files : map [string ]string {
9082+ "/entry.js" : `
9083+ import { "some import" as someImport } from "./foo"
9084+ export { someImport as "some export" }
9085+ export * as "all the stuff" from "./foo"
9086+ ` ,
9087+ },
9088+ entryPaths : []string {"/entry.js" },
9089+ options : config.Options {
9090+ Mode : config .ModeConvertFormat ,
9091+ AbsOutputFile : "/out.js" ,
9092+ OutputFormat : config .FormatIIFE ,
9093+ UnsupportedJSFeatures : compat .ArbitraryModuleNamespaceNames ,
9094+ GlobalName : []string {"global" , "name" },
9095+ },
9096+ })
9097+ }
0 commit comments