forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request webpack#3297 from Kovensky/template-strings
Implement support for template strings in System.import
- Loading branch information
Showing
12 changed files
with
212 additions
and
11 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "ok"; |
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,20 @@ | ||
|
||
it("should parse template strings in amd requires", function(done) { | ||
var name = "abc"; | ||
var suffix = "Test"; | ||
|
||
var pending = [ | ||
require([`./abc/abcTest`], test), | ||
require([`./abc/${name}Test`], test), | ||
require([`./${name}/${name}Test`], test), | ||
require([`./abc/${name}${suffix}`], test), | ||
require([String.raw`./${name}/${name}${suffix}`], test) | ||
].length; | ||
|
||
function test (result) { | ||
result.default.should.eql("ok") | ||
if (--pending <= 0) { | ||
done() | ||
} | ||
} | ||
}) |
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,45 @@ | ||
|
||
it("should parse template strings in require.ensure requires", function(done) { | ||
var name = "abc"; | ||
var suffix = "Test"; | ||
|
||
require.ensure([], function(require) { | ||
var imports = [ | ||
require(`./abc/${name}Test`), | ||
require(`./abc/${name}Test`), | ||
require(`./${name}/${name}Test`), | ||
require(`./abc/${name}${suffix}`), | ||
require(String.raw`./${name}/${name}${suffix}`) | ||
]; | ||
|
||
for (var i = 0; i < imports.length; i++) { | ||
imports[i].default.should.eql("ok"); | ||
} | ||
done() | ||
}) | ||
}) | ||
|
||
it("should parse template strings in sync requires", function() { | ||
var name = "sync"; | ||
var suffix = "Test"; | ||
|
||
var imports = [ | ||
require(`./sync/${name}Test`), | ||
require(`./sync/${name}${suffix}`), | ||
require(String.raw`./sync/${name.slice(0, 1)}y${name.slice(2)}${suffix}`), | ||
require(`./sync/sync${"Test"}`), | ||
require(String.raw`./sync/${"sync"}Test`) | ||
]; | ||
|
||
for (var i = 0; i < imports.length; i++) { | ||
imports[i].default.should.eql("sync"); | ||
} | ||
}) | ||
|
||
it("should parse template strings in require.resolve", function() { | ||
var name = "sync"; | ||
|
||
// Arbitrary assertion; can't use .ok() as it could be 0, | ||
// can't use typeof as that depends on webpack config. | ||
require.resolve(`./sync/${name}Test`).should.not.be.undefined; | ||
}) |
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,20 @@ | ||
var should = require('should') | ||
|
||
it("should parse template strings in System.import", function(done) { | ||
var name = "abc".split(""); | ||
var suffix = "Test"; | ||
Promise.all([ | ||
System.import(`./abc/${name[0]}${name[1]}${name[2]}Test`), | ||
System.import(String.raw`./${name.join("")}/${name.join("")}Test`), | ||
System.import(String.raw`./abc/${name.join("")}${suffix}`) | ||
]) | ||
.then(function (imports) { | ||
for (var i = 0; i < imports.length; i++) { | ||
imports[i].default.should.eql("ok"); | ||
} | ||
}) | ||
.then(function () { done(); }, done) | ||
}); | ||
|
||
require("./cjs") | ||
require("./amd") |
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 @@ | ||
export default "sync"; |
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,5 @@ | ||
var supportsTemplateStrings = require("../../../helpers/supportsTemplateStrings"); | ||
|
||
module.exports = function(config) { | ||
return !config.minimize && supportsTemplateStrings(); | ||
}; |
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 @@ | ||
module.exports = function supportsTemplateStrings() { | ||
try { | ||
var f = eval("(function f() { return String.raw`a\\b`; })"); | ||
return f() === "a\\b"; | ||
} catch(e) { | ||
return false; | ||
} | ||
}; |