parse import.meta correctly (#4836)
This commit is contained in:
@@ -854,7 +854,8 @@ function parse($TEXT, options) {
|
|||||||
next();
|
next();
|
||||||
return export_();
|
return export_();
|
||||||
case "import":
|
case "import":
|
||||||
if (!is_token(peek(), "punc", "(")) {
|
var token = peek();
|
||||||
|
if (!(token.type == "punc" && /^[(.]$/.test(token.value))) {
|
||||||
next();
|
next();
|
||||||
return import_();
|
return import_();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,13 +54,22 @@ dynamic_nought: {
|
|||||||
expect_exact: "import(foo);"
|
expect_exact: "import(foo);"
|
||||||
}
|
}
|
||||||
|
|
||||||
import_meta: {
|
import_meta_1: {
|
||||||
input: {
|
input: {
|
||||||
console.log(import.meta, import.meta.url);
|
console.log(import.meta, import.meta.url);
|
||||||
}
|
}
|
||||||
expect_exact: "console.log(import.meta,import.meta.url);"
|
expect_exact: "console.log(import.meta,import.meta.url);"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import_meta_2: {
|
||||||
|
input: {
|
||||||
|
import.meta.url.split("/").forEach(function(part, index) {
|
||||||
|
console.log(index, part);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_exact: 'import.meta.url.split("/").forEach(function(part,index){console.log(index,part)});'
|
||||||
|
}
|
||||||
|
|
||||||
same_quotes: {
|
same_quotes: {
|
||||||
beautify = {
|
beautify = {
|
||||||
beautify: true,
|
beautify: true,
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ exports.patch_module_statements = function(code) {
|
|||||||
if (!header) return "";
|
if (!header) return "";
|
||||||
if (header.length == 1) return "0, " + header;
|
if (header.length == 1) return "0, " + header;
|
||||||
return header.slice(0, -1) + " _" + ++count + header.slice(-1);
|
return header.slice(0, -1) + " _" + ++count + header.slice(-1);
|
||||||
|
}).replace(/\bimport\.meta\b/g, function() {
|
||||||
|
return '({ url: "https://example.com/path/index.html" })';
|
||||||
}).replace(/\bimport\b(?:\s*([^('"]+)\bfrom\b)?\s*(['"]).*?\2(?:$|\n|;)/g, function(match, symbols) {
|
}).replace(/\bimport\b(?:\s*([^('"]+)\bfrom\b)?\s*(['"]).*?\2(?:$|\n|;)/g, function(match, symbols) {
|
||||||
if (symbols) {
|
if (symbols) {
|
||||||
if (!/^[{*]/.test(symbols)) symbols = "default:" + symbols;
|
if (!/^[{*]/.test(symbols)) symbols = "default:" + symbols;
|
||||||
@@ -220,7 +222,7 @@ function setup(global, builtins, setup_log, setup_tty) {
|
|||||||
if (arg === global) return "[object global]";
|
if (arg === global) return "[object global]";
|
||||||
if (/Error$/.test(arg.name)) return arg.toString();
|
if (/Error$/.test(arg.name)) return arg.toString();
|
||||||
if (typeof arg.then == "function") return "[object Promise]";
|
if (typeof arg.then == "function") return "[object Promise]";
|
||||||
arg.constructor.toString();
|
if (arg.constructor) arg.constructor.toString();
|
||||||
var index = cache.original.indexOf(arg);
|
var index = cache.original.indexOf(arg);
|
||||||
if (index >= 0) return cache.replaced[index];
|
if (index >= 0) return cache.replaced[index];
|
||||||
if (--cache.level < 0) return "[object Object]";
|
if (--cache.level < 0) return "[object Object]";
|
||||||
|
|||||||
@@ -204,12 +204,18 @@ var VALUES = [
|
|||||||
'"function"',
|
'"function"',
|
||||||
"this",
|
"this",
|
||||||
];
|
];
|
||||||
|
VALUES = VALUES.concat(VALUES);
|
||||||
|
VALUES = VALUES.concat(VALUES);
|
||||||
if (SUPPORT.bigint) VALUES = VALUES.concat([
|
if (SUPPORT.bigint) VALUES = VALUES.concat([
|
||||||
"(!0o644n)",
|
"(!0o644n)",
|
||||||
"([3n][0] > 2)",
|
"([3n][0] > 2)",
|
||||||
"(-42n).toString()",
|
"(-42n).toString()",
|
||||||
"Number(0XDEADn << 16n | 0xbeefn)",
|
"Number(0XDEADn << 16n | 0xbeefn)",
|
||||||
]);
|
]);
|
||||||
|
VALUES = VALUES.concat(VALUES);
|
||||||
|
VALUES = VALUES.concat(VALUES);
|
||||||
|
VALUES = VALUES.concat(VALUES);
|
||||||
|
VALUES.push("import.meta");
|
||||||
|
|
||||||
var BINARY_OPS = [
|
var BINARY_OPS = [
|
||||||
" + ", // spaces needed to disambiguate with ++ cases (could otherwise cause syntax errors)
|
" + ", // spaces needed to disambiguate with ++ cases (could otherwise cause syntax errors)
|
||||||
|
|||||||
Reference in New Issue
Block a user