feat: refactoring project
This commit is contained in:
94
node_modules/terser/lib/mozilla-ast.js
generated
vendored
94
node_modules/terser/lib/mozilla-ast.js
generated
vendored
@@ -181,23 +181,23 @@ import { is_basic_identifier_string } from "./parse.js";
|
||||
return body;
|
||||
};
|
||||
|
||||
const assert_clause_from_moz = (assertions) => {
|
||||
if (assertions && assertions.length > 0) {
|
||||
function import_attributes_from_moz(attributes) {
|
||||
if (attributes && attributes.length > 0) {
|
||||
return new AST_Object({
|
||||
start: my_start_token(assertions),
|
||||
end: my_end_token(assertions),
|
||||
properties: assertions.map((assertion_kv) =>
|
||||
start: my_start_token(attributes),
|
||||
end: my_end_token(attributes),
|
||||
properties: attributes.map((attr) =>
|
||||
new AST_ObjectKeyVal({
|
||||
start: my_start_token(assertion_kv),
|
||||
end: my_end_token(assertion_kv),
|
||||
key: assertion_kv.key.name || assertion_kv.key.value,
|
||||
value: from_moz(assertion_kv.value)
|
||||
start: my_start_token(attr),
|
||||
end: my_end_token(attr),
|
||||
key: attr.key.name || attr.key.value,
|
||||
value: from_moz(attr.value)
|
||||
})
|
||||
)
|
||||
});
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
var MOZ_TO_ME = {
|
||||
Program: function(M) {
|
||||
@@ -569,7 +569,7 @@ import { is_basic_identifier_string } from "./parse.js";
|
||||
imported_name: imported_name,
|
||||
imported_names : imported_names,
|
||||
module_name : from_moz(M.source),
|
||||
assert_clause: assert_clause_from_moz(M.assertions)
|
||||
attributes: import_attributes_from_moz(M.attributes || M.assertions)
|
||||
});
|
||||
},
|
||||
|
||||
@@ -595,6 +595,23 @@ import { is_basic_identifier_string } from "./parse.js";
|
||||
});
|
||||
},
|
||||
|
||||
ImportExpression: function(M) {
|
||||
const args = [from_moz(M.source)];
|
||||
if (M.options) {
|
||||
args.push(from_moz(M.options));
|
||||
}
|
||||
return new AST_Call({
|
||||
start: my_start_token(M),
|
||||
end: my_end_token(M),
|
||||
expression: from_moz({
|
||||
type: "Identifier",
|
||||
name: "import"
|
||||
}),
|
||||
optional: false,
|
||||
args
|
||||
});
|
||||
},
|
||||
|
||||
ExportAllDeclaration: function(M) {
|
||||
var foreign_name = M.exported == null ?
|
||||
new AST_SymbolExportForeign({ name: "*" }) :
|
||||
@@ -609,7 +626,7 @@ import { is_basic_identifier_string } from "./parse.js";
|
||||
})
|
||||
],
|
||||
module_name: from_moz(M.source),
|
||||
assert_clause: assert_clause_from_moz(M.assertions)
|
||||
attributes: import_attributes_from_moz(M.attributes || M.assertions)
|
||||
});
|
||||
},
|
||||
|
||||
@@ -620,7 +637,7 @@ import { is_basic_identifier_string } from "./parse.js";
|
||||
exported_definition: from_moz(M.declaration),
|
||||
exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(from_moz) : null,
|
||||
module_name: from_moz(M.source),
|
||||
assert_clause: assert_clause_from_moz(M.assertions)
|
||||
attributes: import_attributes_from_moz(M.attributes || M.assertions)
|
||||
});
|
||||
},
|
||||
|
||||
@@ -662,6 +679,11 @@ import { is_basic_identifier_string } from "./parse.js";
|
||||
args.value = { source, flags };
|
||||
return new AST_RegExp(args);
|
||||
}
|
||||
const bi = typeof M.value === "bigint" ? M.value.toString() : M.bigint;
|
||||
if (typeof bi === "string") {
|
||||
args.value = bi;
|
||||
return new AST_BigInt(args);
|
||||
}
|
||||
if (val === null) return new AST_Null(args);
|
||||
switch (typeof val) {
|
||||
case "string":
|
||||
@@ -729,14 +751,6 @@ import { is_basic_identifier_string } from "./parse.js";
|
||||
});
|
||||
},
|
||||
|
||||
BigIntLiteral(M) {
|
||||
return new AST_BigInt({
|
||||
start : my_start_token(M),
|
||||
end : my_end_token(M),
|
||||
value : M.value
|
||||
});
|
||||
},
|
||||
|
||||
EmptyStatement: function(M) {
|
||||
return new AST_EmptyStatement({
|
||||
start: my_start_token(M),
|
||||
@@ -1209,6 +1223,15 @@ import { is_basic_identifier_string } from "./parse.js";
|
||||
};
|
||||
});
|
||||
def_to_moz(AST_Call, function To_Moz_CallExpression(M) {
|
||||
if (M.expression instanceof AST_SymbolRef && M.expression.name === "import") {
|
||||
const [source, options] = M.args.map(to_moz);
|
||||
return {
|
||||
type: "ImportExpression",
|
||||
source,
|
||||
options
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: "CallExpression",
|
||||
callee: to_moz(M.expression),
|
||||
@@ -1366,22 +1389,22 @@ import { is_basic_identifier_string } from "./parse.js";
|
||||
};
|
||||
});
|
||||
|
||||
const assert_clause_to_moz = assert_clause => {
|
||||
const assertions = [];
|
||||
if (assert_clause) {
|
||||
for (const { key, value } of assert_clause.properties) {
|
||||
function import_attributes_to_moz(attribute) {
|
||||
const import_attributes = [];
|
||||
if (attribute) {
|
||||
for (const { key, value } of attribute.properties) {
|
||||
const key_moz = is_basic_identifier_string(key)
|
||||
? { type: "Identifier", name: key }
|
||||
: { type: "Literal", value: key, raw: JSON.stringify(key) };
|
||||
assertions.push({
|
||||
import_attributes.push({
|
||||
type: "ImportAttribute",
|
||||
key: key_moz,
|
||||
value: to_moz(value)
|
||||
});
|
||||
}
|
||||
}
|
||||
return assertions;
|
||||
};
|
||||
return import_attributes;
|
||||
}
|
||||
|
||||
def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {
|
||||
if (M.exported_names) {
|
||||
@@ -1396,7 +1419,7 @@ import { is_basic_identifier_string } from "./parse.js";
|
||||
type: "ExportAllDeclaration",
|
||||
source: to_moz(M.module_name),
|
||||
exported: exported,
|
||||
assertions: assert_clause_to_moz(M.assert_clause)
|
||||
attributes: import_attributes_to_moz(M.attributes)
|
||||
};
|
||||
}
|
||||
return {
|
||||
@@ -1410,7 +1433,7 @@ import { is_basic_identifier_string } from "./parse.js";
|
||||
}),
|
||||
declaration: to_moz(M.exported_definition),
|
||||
source: to_moz(M.module_name),
|
||||
assertions: assert_clause_to_moz(M.assert_clause)
|
||||
attributes: import_attributes_to_moz(M.attributes)
|
||||
};
|
||||
}
|
||||
return {
|
||||
@@ -1448,7 +1471,7 @@ import { is_basic_identifier_string } from "./parse.js";
|
||||
type: "ImportDeclaration",
|
||||
specifiers: specifiers,
|
||||
source: to_moz(M.module_name),
|
||||
assertions: assert_clause_to_moz(M.assert_clause)
|
||||
attributes: import_attributes_to_moz(M.attributes)
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1754,8 +1777,13 @@ import { is_basic_identifier_string } from "./parse.js";
|
||||
});
|
||||
|
||||
def_to_moz(AST_BigInt, M => ({
|
||||
type: "BigIntLiteral",
|
||||
value: M.value
|
||||
type: "Literal",
|
||||
// value cannot be represented natively
|
||||
// see: https://github.com/estree/estree/blob/master/es2020.md#bigintliteral
|
||||
value: null,
|
||||
// `M.value` is a string that may be a hex number representation.
|
||||
// but "bigint" property should have only decimal digits
|
||||
bigint: typeof BigInt === "function" ? BigInt(M.value).toString() : M.value,
|
||||
}));
|
||||
|
||||
AST_Boolean.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);
|
||||
|
||||
Reference in New Issue
Block a user