+5
-0
| # Changelog | ||
| ## v5.47.0 | ||
| - Add `builtins_ecma` and `builtins_pure` options | ||
| - Add Intl options to domprops (#1680) | ||
| ## v5.46.2 | ||
@@ -4,0 +9,0 @@ |
@@ -78,3 +78,2 @@ /*********************************************************************** | ||
| import { is_undeclared_ref} from "./inference.js"; | ||
| import { is_pure_native_value, is_pure_native_fn, is_pure_native_method } from "./native-objects.js"; | ||
@@ -443,3 +442,3 @@ // methods to evaluate a constant expression | ||
| } | ||
| if (!is_pure_native_value(exp.name, key)) | ||
| if (!compressor.is_pure_native_static_property(exp.name, key)) | ||
| return this; | ||
@@ -500,3 +499,3 @@ obj = global_objs[exp.name]; | ||
| } | ||
| if (!is_pure_native_fn(e.name, key)) return this; | ||
| if (!compressor.is_pure_native_static_fn(e.name, key)) return this; | ||
| val = global_objs[e.name]; | ||
@@ -508,3 +507,3 @@ } else { | ||
| return this; | ||
| if (!is_pure_native_method(val.constructor.name, key)) | ||
| if (!compressor.is_pure_native_method(val.constructor.name, key)) | ||
| return this; | ||
@@ -511,0 +510,0 @@ } |
@@ -131,3 +131,3 @@ /*********************************************************************** | ||
| import { INLINED, UNDEFINED, has_flag } from "./compressor-flags.js"; | ||
| import { pure_prop_access_globals, is_pure_native_fn, is_pure_native_method } from "./native-objects.js"; | ||
| import { is_pure_builtin_call, pure_prop_access_globals } from "./native-objects.js"; | ||
@@ -973,9 +973,5 @@ // Functions and methods to infer certain facts about expressions | ||
| if (is_undeclared_ref(expr) && global_pure_fns.has(expr.name)) return true; | ||
| if ( | ||
| expr instanceof AST_Dot | ||
| && is_undeclared_ref(expr.expression) | ||
| && is_pure_native_fn(expr.expression.name, expr.property) | ||
| ) { | ||
| return true; | ||
| } | ||
| if (is_pure_builtin_call(compressor, this)) return true; | ||
| } else if (compressor.option("builtins_pure")) { | ||
| if (is_pure_builtin_call(compressor, this)) return true; | ||
| } | ||
@@ -1011,3 +1007,3 @@ if ((this instanceof AST_New) && compressor.option("pure_new")) { | ||
| } | ||
| return native_obj != null && is_pure_native_method(native_obj, this.property); | ||
| return native_obj != null && compressor.is_pure_native_method(native_obj, this.property); | ||
| }); | ||
@@ -1014,0 +1010,0 @@ |
@@ -44,3 +44,5 @@ /*********************************************************************** | ||
| import { AST_Array, AST_Dot, AST_New, AST_Number, AST_SymbolRef } from "../ast.js"; | ||
| import { makePredicate } from "../utils/index.js"; | ||
| import { is_undeclared_ref } from "./inference.js"; | ||
@@ -51,6 +53,10 @@ // Lists of native methods, useful for `unsafe` option which assumes they exist. | ||
| function make_nested_lookup(obj) { | ||
| const make_nested_lookup = (feature_callback) => (compressor) => { | ||
| const obj = feature_callback(feature_variables(compressor)); | ||
| const out = new Map(); | ||
| for (var key of Object.keys(obj)) { | ||
| out.set(key, makePredicate(obj[key])); | ||
| if (obj[key]) { | ||
| out.set(key, makePredicate(remove_false(obj[key]))); | ||
| } | ||
| } | ||
@@ -63,4 +69,70 @@ | ||
| return does_have; | ||
| }; | ||
| const make_lookup = (feature_callback) => (compressor) => { | ||
| const obj = feature_callback(feature_variables(compressor)); | ||
| const predicate = makePredicate(remove_false(obj)); | ||
| const does_have = (global_name) => { | ||
| return predicate.has(global_name); | ||
| }; | ||
| return does_have; | ||
| }; | ||
| function remove_false(arr) { | ||
| for (let i = 0; i < arr.length; i++) { | ||
| if (arr[i] === false) { | ||
| arr.splice(i, 1); | ||
| i--; | ||
| } | ||
| } | ||
| return arr; | ||
| } | ||
| /** Generate the object with arguments seen below */ | ||
| function feature_variables(compressor) { | ||
| return { | ||
| sloppy: compressor.option("unsafe"), | ||
| es: compressor.option("builtins_ecma"), | ||
| }; | ||
| } | ||
| // eslint-disable-next-line no-unused-vars | ||
| export const pure_access_globals = make_lookup(({ sloppy, es }) => [ | ||
| "Array", | ||
| "Boolean", | ||
| "clearInterval", | ||
| "clearTimeout", | ||
| "console", | ||
| "Date", | ||
| "decodeURI", | ||
| "decodeURIComponent", | ||
| "encodeURI", | ||
| "encodeURIComponent", | ||
| "Error", | ||
| "escape", | ||
| "eval", | ||
| "EvalError", | ||
| "Function", | ||
| es >= 2020 && "globalThis", | ||
| "isFinite", | ||
| "isNaN", | ||
| "JSON", | ||
| "Math", | ||
| "Number", | ||
| "parseFloat", | ||
| "parseInt", | ||
| "RangeError", | ||
| "ReferenceError", | ||
| "RegExp", | ||
| "Object", | ||
| "setInterval", | ||
| "setTimeout", | ||
| "String", | ||
| "SyntaxError", | ||
| "TypeError", | ||
| "unescape", | ||
| "URIError", | ||
| ]); | ||
| // Objects which are safe to access without throwing or causing a side effect. | ||
@@ -77,2 +149,74 @@ // Usually we'd check the `unsafe` option first but these are way too common for that | ||
| // eslint-disable-next-line no-unused-vars | ||
| export const is_pure_native_fn = make_lookup(({ sloppy, es }) => [ | ||
| sloppy && es >= 2021 && "AggregateError", | ||
| "Array", | ||
| "ArrayBuffer", | ||
| es >= 2020 && "BigInt", | ||
| es >= 2020 && "BigInt64Array", | ||
| es >= 2020 && "BigUint64Array", | ||
| "Boolean", | ||
| "Date", | ||
| sloppy && "decodeURI", | ||
| sloppy && "decodeURIComponent", | ||
| sloppy && "encodeURI", | ||
| sloppy && "encodeURIComponent", | ||
| "Error", | ||
| "escape", | ||
| "EvalError", | ||
| es >= 2021 && "FinalizationRegistry", | ||
| es >= 2026 && "Float16Array", | ||
| "Float32Array", | ||
| "Float64Array", | ||
| "Int16Array", | ||
| "Int32Array", | ||
| "Int8Array", | ||
| "isFinite", | ||
| "isNaN", | ||
| es >= 2026 && "Iterator", | ||
| es >= 2015 && "Map", | ||
| "Number", | ||
| "parseFloat", | ||
| "parseInt", | ||
| es >= 2015 && "Promise", | ||
| es >= 2015 && "Proxy", | ||
| "RangeError", | ||
| "ReferenceError", | ||
| sloppy && "RegExp", | ||
| es >= 2015 && "Set", | ||
| "String", | ||
| es >= 2015 && "Symbol", | ||
| "SyntaxError", | ||
| "TypeError", | ||
| "Uint16Array", | ||
| "Uint32Array", | ||
| "Uint8Array", | ||
| "Uint8ClampedArray", | ||
| sloppy && "unescape", | ||
| "URIError", | ||
| sloppy && es >= 2015 && "WeakMap", | ||
| sloppy && es >= 2021 && "WeakRef", | ||
| sloppy && es >= 2015 && "WeakSet", | ||
| ]); | ||
| const arg1_is_iterable = new Set([ | ||
| "Map", | ||
| "Set", | ||
| "WeakMap", | ||
| "WeakSet", | ||
| ]); | ||
| const arg1_is_range_or_iterable = new Set([ | ||
| "ArrayBuffer", | ||
| "Float32Array", | ||
| "Float64Array", | ||
| "Int16Array", | ||
| "Int32Array", | ||
| "Int8Array", | ||
| "Uint16Array", | ||
| "Uint32Array", | ||
| "Uint8Array", | ||
| "Uint8ClampedArray", | ||
| ]); | ||
| const lone_arg_is_range = new Set(["Array"]); | ||
| const object_methods = [ | ||
@@ -84,7 +228,8 @@ "constructor", | ||
| export const is_pure_native_method = make_nested_lookup({ | ||
| // eslint-disable-next-line no-unused-vars | ||
| export const is_pure_native_method = make_nested_lookup(({ sloppy, es }) => ({ | ||
| Array: [ | ||
| "at", | ||
| "flat", | ||
| "includes", | ||
| es >= 2022 && "at", | ||
| es >= 2019 && "flat", | ||
| es >= 2016 && "includes", | ||
| "indexOf", | ||
@@ -110,30 +255,28 @@ "join", | ||
| String: [ | ||
| "at", | ||
| es >= 2022 && "at", | ||
| "charAt", | ||
| "charCodeAt", | ||
| "charPointAt", | ||
| es >= 2015 && "codePointAt", | ||
| "concat", | ||
| "endsWith", | ||
| "fromCharCode", | ||
| "fromCodePoint", | ||
| "includes", | ||
| es >= 2025 && "endsWith", | ||
| es >= 2015 && "includes", | ||
| "indexOf", | ||
| "italics", | ||
| "lastIndexOf", | ||
| "localeCompare", | ||
| es >= 2020 && "localeCompare", | ||
| "match", | ||
| "matchAll", | ||
| "normalize", | ||
| "padStart", | ||
| "padEnd", | ||
| "repeat", | ||
| es >= 2020 && "matchAll", | ||
| es >= 2015 && "normalize", | ||
| es >= 2017 && "padStart", | ||
| es >= 2017 && "padEnd", | ||
| es >= 2015 && sloppy && "repeat", | ||
| "replace", | ||
| "replaceAll", | ||
| es >= 2021 && "replaceAll", | ||
| "search", | ||
| "slice", | ||
| "split", | ||
| "startsWith", | ||
| es >= 2015 && "startsWith", | ||
| "substr", | ||
| "substring", | ||
| "repeat", | ||
| es >= 2015 && "repeat", | ||
| "toLocaleLowerCase", | ||
@@ -144,53 +287,125 @@ "toLocaleUpperCase", | ||
| "trim", | ||
| "trimEnd", | ||
| "trimStart", | ||
| es >= 2019 && "trimEnd", | ||
| es >= 2019 && "trimStart", | ||
| es >= 2019 && "trimLeft", | ||
| es >= 2019 && "trimRight", | ||
| ...object_methods, | ||
| ], | ||
| }); | ||
| })); | ||
| export const is_pure_native_fn = make_nested_lookup({ | ||
| // eslint-disable-next-line no-unused-vars | ||
| export const is_pure_native_static_fn = make_nested_lookup(({ sloppy, es }) => ({ | ||
| Array: [ | ||
| "isArray", | ||
| es >= 2015 && "of", | ||
| ], | ||
| ArrayBuffer: [ | ||
| "isView", | ||
| ], | ||
| BigInt: es >= 2020 && [ | ||
| sloppy && "asIntN", | ||
| sloppy && "asUintN", | ||
| ], | ||
| BigInt64Array: sloppy && es >= 2020 && ["of"], | ||
| BigUint64Array: sloppy && es >= 2020 && ["of"], | ||
| Date: [ | ||
| "now", | ||
| "parse", | ||
| "UTC", | ||
| ], | ||
| Error: [ | ||
| es >= 2026 && "isError", | ||
| ], | ||
| Float16Array: sloppy && es >= 2026 && ["of"], | ||
| Float32Array: sloppy && ["of"], | ||
| Float64Array: sloppy && ["of"], | ||
| Int16Array: sloppy && ["of"], | ||
| Int32Array: sloppy && ["of"], | ||
| Int8Array: sloppy && ["of"], | ||
| Math: [ | ||
| "abs", | ||
| "acos", | ||
| es >= 2015 && "acosh", | ||
| "asin", | ||
| es >= 2015 && "asinh", | ||
| "atan", | ||
| "atan2", | ||
| es >= 2015 && "atanh", | ||
| es >= 2015 && "cbrt", | ||
| "ceil", | ||
| es >= 2015 && "clz32", | ||
| "cos", | ||
| es >= 2015 && "cosh", | ||
| "exp", | ||
| es >= 2015 && "expm1", | ||
| "floor", | ||
| es >= 2026 && "f16round", | ||
| es >= 2015 && "fround", | ||
| es >= 2015 && "hypot", | ||
| es >= 2015 && "imul", | ||
| "log", | ||
| es >= 2015 && "log10", | ||
| es >= 2015 && "log1p", | ||
| es >= 2015 && "log2", | ||
| "max", | ||
| "min", | ||
| "pow", | ||
| "round", | ||
| es >= 2015 && "sign", | ||
| "sin", | ||
| es >= 2015 && "sinh", | ||
| "sqrt", | ||
| "tan", | ||
| "atan2", | ||
| "pow", | ||
| "max", | ||
| "min", | ||
| es >= 2015 && "tanh", | ||
| es >= 2015 && "trunc", | ||
| ], | ||
| Number: [ | ||
| "isFinite", | ||
| "isNaN", | ||
| es >= 2015 && "isFinite", | ||
| es >= 2015 && "isInteger", | ||
| es >= 2015 && "isSafeInteger", | ||
| es >= 2015 && "isNaN", | ||
| es >= 2015 && "parseFloat", | ||
| es >= 2015 && "parseInt", | ||
| ], | ||
| Object: [ | ||
| "create", | ||
| "getOwnPropertyDescriptor", | ||
| "getOwnPropertyNames", | ||
| "getPrototypeOf", | ||
| sloppy && "create", | ||
| sloppy && "getOwnPropertyDescriptor", | ||
| es >= 2017 && sloppy && "getOwnPropertyDescriptors", | ||
| sloppy && "getOwnPropertyNames", | ||
| es >= 2015 && sloppy && "getOwnPropertySymbols", | ||
| sloppy && "getPrototypeOf", | ||
| es >= 2022 && sloppy && "hasOwn", | ||
| es >= 2015 && "is", | ||
| "isExtensible", | ||
| "isFrozen", | ||
| "isSealed", | ||
| "hasOwn", | ||
| "keys", | ||
| es >= 2015 && sloppy && "keys", | ||
| ], | ||
| Promise: es >= 2015 && [ | ||
| es >= 2024 && "withResolvers", | ||
| ], | ||
| Proxy: es >= 2015 && [ | ||
| sloppy && "revocable", | ||
| ], | ||
| Reflect: es >= 2015 && [ | ||
| sloppy && "has", | ||
| sloppy && "isExtensible", | ||
| sloppy && "ownKeys", | ||
| ], | ||
| RegExp: [ | ||
| es >= 2026 && sloppy && "escape", | ||
| ], | ||
| String: [ | ||
| "fromCharCode", | ||
| sloppy && es >= 2025 && "fromCodePoint", | ||
| ], | ||
| }); | ||
| Uint16Array: ["of"], | ||
| Uint32Array: ["of"], | ||
| Uint8Array: ["of"], | ||
| Uint8ClampedArray: ["of"], | ||
| })); | ||
| // Known numeric values which come with JS environments | ||
| export const is_pure_native_value = make_nested_lookup({ | ||
| // eslint-disable-next-line no-unused-vars | ||
| export const is_pure_native_static_property = make_nested_lookup(({ sloppy, es }) => ({ | ||
| Math: [ | ||
@@ -207,3 +422,6 @@ "E", | ||
| Number: [ | ||
| es >= 2015 && "EPSILON", | ||
| es >= 2015 && "MAX_SAFE_VALUE", | ||
| "MAX_VALUE", | ||
| es >= 2015 && "MIN_SAFE_VALUE", | ||
| "MIN_VALUE", | ||
@@ -214,2 +432,116 @@ "NaN", | ||
| ], | ||
| }); | ||
| RegExp: [ | ||
| "$_", | ||
| "$0", | ||
| "$1", | ||
| "$2", | ||
| "$3", | ||
| "$4", | ||
| "$5", | ||
| "$6", | ||
| "$7", | ||
| "$8", | ||
| "$9", | ||
| "input", | ||
| "lastMatch", | ||
| "lastParen", | ||
| "leftContext", | ||
| "rightContext", | ||
| ], | ||
| })); | ||
| const re_uppercase_first_letter = /^[A-Z]/; | ||
| export function is_pure_builtin_call(compressor, call) { | ||
| let builtin = ""; | ||
| let method = ""; | ||
| let exp = call.expression; | ||
| if (is_undeclared_ref(exp)) { | ||
| builtin = exp.name; | ||
| } else if (exp instanceof AST_Dot) { | ||
| method = exp.property; | ||
| exp = exp.expression; | ||
| if (is_undeclared_ref(exp)) { | ||
| if ( | ||
| // globalThis.pureFunc() | ||
| exp.name === "globalThis" | ||
| && compressor.option("builtins_ecma") >= 2020 | ||
| ) { | ||
| builtin = method; | ||
| method = ""; | ||
| } else { | ||
| // SomeBuiltin.pureFunc() | ||
| builtin = exp.name; | ||
| } | ||
| } else if (exp instanceof AST_Dot) { | ||
| if ( | ||
| is_undeclared_ref(exp.expression) | ||
| && exp.expression.name === "globalThis" | ||
| && compressor.option("builtins_ecma") >= 2020 | ||
| ) { | ||
| // globalThis.SomeBuiltin.pureFunc() | ||
| builtin = exp.property; | ||
| } else { | ||
| return false; | ||
| } | ||
| } else { | ||
| return false; | ||
| } | ||
| } else { | ||
| return false; | ||
| } | ||
| if (!method) { | ||
| if (compressor.is_pure_native_fn(builtin)) { | ||
| // some require `new`, others throw if you use it | ||
| const is_new = call instanceof AST_New; | ||
| const should_be_new = re_uppercase_first_letter.test(builtin); // true of all `is_pure_native_fn` | ||
| if (is_new !== should_be_new) return false; | ||
| if (!is_builtin_pure_with_these_args(builtin, call.args)) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } else { | ||
| return compressor.is_pure_native_static_fn(builtin, method); | ||
| } | ||
| } | ||
| /** Some builtins are listed above but their purity is subject to some conditions */ | ||
| function is_builtin_pure_with_these_args(builtin, args) { | ||
| // all the builtins we deal with here are ok with getting 0 args | ||
| if (args.length === 0) return true; | ||
| let arg1 = args[0]; | ||
| if (arg1 instanceof AST_SymbolRef) { | ||
| arg1 = arg1.fixed_value(); | ||
| } | ||
| if (lone_arg_is_range.has(builtin)) { // new Array(number) | ||
| const arg_valid = args.length > 1 | ||
| || arg1 instanceof AST_Number | ||
| && arg1.value >= 0 && arg1.value <= 0xffffffff; | ||
| // TODO: or, we are asked to ignore TypeError | ||
| if (!arg_valid) return false; | ||
| } | ||
| if (arg1_is_range_or_iterable.has(builtin)) { // new Float32Array(number | Array) | ||
| const arg_valid = args.length === 0 | ||
| || arg1 instanceof AST_Array | ||
| || arg1 instanceof AST_Number | ||
| && arg1.value >= 0 && arg1.value <= 0xffffffff; | ||
| if (!arg_valid) return false; | ||
| } | ||
| if (arg1_is_iterable.has(builtin)) { // new Set(iterable) | ||
| const arg_valid = args.length === 0 || arg1 instanceof AST_Array; | ||
| if (!arg_valid) return false; | ||
| } | ||
| return true; | ||
| } |
@@ -82,3 +82,3 @@ /*********************************************************************** | ||
| ret[i] = defs[i]; | ||
| } else if (i === "ecma") { | ||
| } else if (i === "ecma" || i === "builtins_ecma") { | ||
| let ecma = args[i] | 0; | ||
@@ -85,0 +85,0 @@ if (ecma > 5 && ecma < 2015) ecma += 2009; |
+1
-1
@@ -7,3 +7,3 @@ { | ||
| "license": "BSD-2-Clause", | ||
| "version": "5.46.2", | ||
| "version": "5.47.0", | ||
| "engines": { | ||
@@ -10,0 +10,0 @@ "node": ">=10" |
+4
-0
@@ -743,2 +743,6 @@ <h1><img src="https://terser.org/img/terser-banner-logo.png" alt="Terser" width="400"></h1> | ||
| - `builtins_ecma` (default: `5`) -- An ES version number (like `ecma`). Tells Terser which well-known functions, constants, methods and classes are available in the global object. Does nothing by itself, but is used by `builtins_pure` and `unsafe`. | ||
| - `builtins_pure` (default: `false`) -- Pass `true` to assume that functions matched by the `builtins_ecma` option (such as `Math.sin` or `unescape`) are pure and calls to them can be removed. | ||
| - `evaluate` (default: `true`) -- attempt to evaluate constant expressions | ||
@@ -745,0 +749,0 @@ |
@@ -5,3 +5,3 @@ /// <reference lib="es2015" /> | ||
| export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020; | ||
| export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | 2025; | ||
@@ -34,2 +34,4 @@ export type ConsoleProperty = keyof typeof console; | ||
| ecma?: ECMA; | ||
| builtins_ecma?: ECMA; | ||
| builtins_pure?: boolean; | ||
| evaluate?: boolean; | ||
@@ -36,0 +38,0 @@ expression?: boolean; |
| import { | ||
| AST_Export, | ||
| AST_Import, | ||
| AST_Toplevel, | ||
| } from "../ast.js"; | ||
| AST_Toplevel.DEFMETHOD("optimize_import_export", function(compressor) { | ||
| if (!compressor.option("import_export")) return; | ||
| // We will compare `stat` against `prev` to see if it's a compatible import/export | ||
| // When compatible, merge! | ||
| let stat_i = 1; | ||
| while (stat_i < this.body.length) { | ||
| const stat = this.body[stat_i]; | ||
| const prev = this.body[stat_i - 1]; | ||
| const merged_import = | ||
| (stat instanceof AST_Import && prev instanceof AST_Import) | ||
| && merge_imports(prev, stat); | ||
| const merged_export = | ||
| (stat instanceof AST_Export && prev instanceof AST_Export) | ||
| && merge_exports(prev, stat); | ||
| if (merged_import || merged_export) { | ||
| this.body.splice(stat_i, 1); | ||
| // Don't stat_i++. We can stay here. | ||
| } else { | ||
| stat_i++; | ||
| } | ||
| } | ||
| }); | ||
| /** Merge a compatible import statement. Or return false */ | ||
| function merge_imports(into, merge_from) { | ||
| if ( | ||
| // same "from" | ||
| into.module_name.value === merge_from.module_name.value | ||
| // only one can have a default import | ||
| && !(into.imported_name && merge_from.imported_name) | ||
| // "*" not supported | ||
| && can_merge_name_mappings(into.imported_names, merge_from.imported_names) | ||
| // "with" not supported | ||
| && !into.attributes && !merge_from.attributes | ||
| ) { | ||
| into.imported_name = into.imported_name || merge_from.imported_name; | ||
| into.imported_names = merge_name_mappings(into.imported_names, merge_from.imported_names); | ||
| return true; // `merge_from` can be safely removed | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
| /** Merge a compatible export statement. Or return false */ | ||
| function merge_exports(into, merge_from) { | ||
| if ( | ||
| // "export function" not supported | ||
| !into.exported_value && !merge_from.exported_value | ||
| // "export from" not supported | ||
| && !into.module_name && !merge_from.module_name | ||
| // "export default" not supported | ||
| && !into.is_default && !merge_from.is_default | ||
| // "with" not supported | ||
| && !into.attributes && !merge_from.attributes | ||
| ) { | ||
| if ( | ||
| // "export { a, b, c }" | ||
| into.exported_names && merge_from.exported_names | ||
| && can_merge_name_mappings(into.exported_names, merge_from.exported_names) | ||
| ) { | ||
| into.exported_names = merge_name_mappings(into.exported_names, merge_from.exported_names); | ||
| return true; | ||
| } else if ( | ||
| // "export var xx" | ||
| into.exported_definition && merge_from.exported_definition | ||
| && can_merge_definitions(into.exported_definition, merge_from.exported_definition) | ||
| ) { | ||
| merge_definitions(into.exported_definition, merge_from.exported_definition); | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
| /** Make sure a and b are optional AST_NameMapping*? arrays without the same names */ | ||
| function can_merge_name_mappings(a, b) { | ||
| for (const mapping_array of [a, b]) { | ||
| for (const mapping of (mapping_array || [])) { | ||
| if (mapping.name.name === "*") return false; | ||
| if (mapping.foreign_name.name === "*") return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| function merge_name_mappings(our_names, their_names) { | ||
| const arr_our_names = our_names || []; | ||
| const arr_their_names = their_names || []; | ||
| if (arr_our_names.length + arr_their_names.length > 0) { | ||
| return arr_our_names.concat(arr_their_names); | ||
| } else { | ||
| return our_names; | ||
| } | ||
| } | ||
| function can_merge_definitions(our_defs, their_defs) { | ||
| return our_defs.TYPE === their_defs.TYPE; | ||
| } | ||
| /** Merge two AST_Definitions */ | ||
| function merge_definitions(our_defs, their_defs) { | ||
| our_defs.definitions.push(...their_defs.definitions); | ||
| } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
2293595
0.72%65732
0.89%1424
0.28%42
-2.33%