From 8df2bc1acb284ff40890de3dadac2b9a5a23b1df Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 16 Aug 2019 08:49:12 +0200 Subject: [PATCH] Update to acorn 7 (#3061) * Update to acorn 7 * Adds test with a meta property other than `import.meta` --- package-lock.json | 57 ++- package.json | 8 +- src/Module.ts | 14 +- .../nodes/{Import.ts => ImportExpression.ts} | 26 +- src/ast/nodes/MetaProperty.ts | 4 + src/ast/nodes/NodeType.ts | 2 + src/ast/nodes/index.ts | 4 +- .../new-target-meta-property/_config.js | 3 + .../new-target-meta-property/_expected.js | 7 + .../samples/new-target-meta-property/main.js | 8 + .../samples/supports-core-js/_expected.js | 333 +++++++++++------- 11 files changed, 296 insertions(+), 170 deletions(-) rename src/ast/nodes/{Import.ts => ImportExpression.ts} (86%) create mode 100644 test/form/samples/new-target-meta-property/_config.js create mode 100644 test/form/samples/new-target-meta-property/_expected.js create mode 100644 test/form/samples/new-target-meta-property/main.js diff --git a/package-lock.json b/package-lock.json index d4f32986fea..6bca8795f6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -245,9 +245,9 @@ "dev": true }, "@types/node": { - "version": "12.7.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.1.tgz", - "integrity": "sha512-aK9jxMypeSrhiYofWWBf/T7O+KwaiAHzM4sveCdWPn71lzUSMimRnKzhXDKfKwV1kWoBo2P1aGgaIYGLf9/ljw==" + "version": "12.7.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.2.tgz", + "integrity": "sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg==" }, "@types/normalize-package-data": { "version": "2.4.0", @@ -282,9 +282,9 @@ "optional": true }, "acorn": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.3.0.tgz", - "integrity": "sha512-/czfa8BwS88b9gWQVhc8eknunSA2DoJpJyTQkhheIf5E48u1N0R4q/YxxsAeqRrmK9TQ/uYfgLDfZo91UlANIA==" + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.0.0.tgz", + "integrity": "sha512-PaF/MduxijYYt7unVGRuds1vBC9bFxbNf+VWqhOClfdgy7RlVkQqt610ig1/yxTgsDIfW1cWDel5EBbOy3jdtQ==" }, "acorn-dynamic-import": { "version": "4.0.0", @@ -305,9 +305,9 @@ "dev": true }, "acorn-walk": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.2.0.tgz", - "integrity": "sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-7.0.0.tgz", + "integrity": "sha512-7Bv1We7ZGuU79zZbb6rRqcpxo3OY+zrdtloZWoyD8fmGX+FeXRjE+iuGkZjSXLVovLzrsvMGMy0EkwA0E0umxg==", "dev": true }, "agent-base": { @@ -646,6 +646,12 @@ "regexpu-core": "^4.5.4" }, "dependencies": { + "acorn": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.3.0.tgz", + "integrity": "sha512-/czfa8BwS88b9gWQVhc8eknunSA2DoJpJyTQkhheIf5E48u1N0R4q/YxxsAeqRrmK9TQ/uYfgLDfZo91UlANIA==", + "dev": true + }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -1017,7 +1023,8 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "dev": true + "dev": true, + "optional": true }, "console-group": { "version": "0.3.3", @@ -1047,9 +1054,9 @@ "dev": true }, "core-js": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.1.4.tgz", - "integrity": "sha512-YNZN8lt82XIMLnLirj9MhKDFZHalwzzrL9YLt6eb0T5D0EDl4IQ90IGkua8mHbnxNrkj1d8hbdizMc0Qmg1WnQ==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.2.1.tgz", + "integrity": "sha512-Qa5XSVefSVPRxy2XfUC13WbvqkxhkwB3ve+pgCQveNgYzbM/UxZeu1dcOX/xr4UmfUd+muuvsaxilQzCyUurMw==", "dev": true }, "core-util-is": { @@ -1624,6 +1631,14 @@ "acorn": "^6.0.7", "acorn-jsx": "^5.0.0", "eslint-visitor-keys": "^1.0.0" + }, + "dependencies": { + "acorn": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.3.0.tgz", + "integrity": "sha512-/czfa8BwS88b9gWQVhc8eknunSA2DoJpJyTQkhheIf5E48u1N0R4q/YxxsAeqRrmK9TQ/uYfgLDfZo91UlANIA==", + "dev": true + } } }, "esprima": { @@ -2222,7 +2237,8 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true + "dev": true, + "optional": true }, "is-fullwidth-code-point": { "version": "1.0.0", @@ -2251,6 +2267,7 @@ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3848,6 +3865,7 @@ "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz", "integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==", "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -5079,6 +5097,14 @@ "@types/estree": "0.0.39", "@types/node": "^12.6.9", "acorn": "^6.2.1" + }, + "dependencies": { + "acorn": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.3.0.tgz", + "integrity": "sha512-/czfa8BwS88b9gWQVhc8eknunSA2DoJpJyTQkhheIf5E48u1N0R4q/YxxsAeqRrmK9TQ/uYfgLDfZo91UlANIA==", + "dev": true + } } }, "rollup-plugin-alias": { @@ -6316,7 +6342,8 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==", - "dev": true + "dev": true, + "optional": true }, "yargs": { "version": "13.2.2", diff --git a/package.json b/package.json index f09a3f36acd..86cc5570241 100644 --- a/package.json +++ b/package.json @@ -58,8 +58,8 @@ "homepage": "https://github.com/rollup/rollup", "dependencies": { "@types/estree": "0.0.39", - "@types/node": "^12.7.1", - "acorn": "^6.3.0" + "@types/node": "^12.7.2", + "acorn": "^7.0.0" }, "devDependencies": { "@types/chokidar": "^2.1.3", @@ -67,12 +67,12 @@ "@types/minimist": "^1.2.0", "acorn-import-meta": "^1.0.0", "acorn-jsx": "^5.0.1", - "acorn-walk": "^6.2.0", + "acorn-walk": "^7.0.0", "buble": "^0.19.8", "chokidar": "^2.1.6", "codecov": "^3.5.0", "console-group": "^0.3.3", - "core-js": "^3.1.4", + "core-js": "^3.2.1", "date-time": "^3.1.0", "es5-shim": "^4.5.13", "es6-shim": "^0.35.5", diff --git a/src/Module.ts b/src/Module.ts index d48d25d1d2e..4b2bdb9f7d4 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -9,8 +9,8 @@ import ExportDefaultDeclaration from './ast/nodes/ExportDefaultDeclaration'; import ExportNamedDeclaration from './ast/nodes/ExportNamedDeclaration'; import FunctionDeclaration from './ast/nodes/FunctionDeclaration'; import Identifier from './ast/nodes/Identifier'; -import Import from './ast/nodes/Import'; import ImportDeclaration from './ast/nodes/ImportDeclaration'; +import ImportExpression from './ast/nodes/ImportExpression'; import ImportSpecifier from './ast/nodes/ImportSpecifier'; import { nodeConstructors } from './ast/nodes/index'; import Literal from './ast/nodes/Literal'; @@ -80,7 +80,7 @@ export interface ReexportDescription { } export interface AstContext { - addDynamicImport: (node: Import) => void; + addDynamicImport: (node: ImportExpression) => void; addExport: ( node: ExportAllDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration ) => void; @@ -97,7 +97,7 @@ export interface AstContext { getModuleName: () => string; getReexports: () => string[]; importDescriptions: { [name: string]: ImportDescription }; - includeDynamicImport: (node: Import) => void; + includeDynamicImport: (node: ImportExpression) => void; includeVariable: (variable: Variable) => void; isCrossChunkImport: (importDescription: ImportDescription) => boolean; magicString: MagicString; @@ -178,7 +178,7 @@ export default class Module { dynamicallyImportedBy: Module[] = []; dynamicDependencies: (Module | ExternalModule)[] = []; dynamicImports: { - node: Import; + node: ImportExpression; resolution: Module | ExternalModule | string | null; }[] = []; entryPointsHash: Uint8Array = new Uint8Array(10); @@ -302,7 +302,7 @@ export default class Module { getDynamicImportExpressions(): (string | Node)[] { return this.dynamicImports.map(({ node }) => { - const importArgument = node.parent.arguments[0]; + const importArgument = node.source; if ( importArgument instanceof TemplateLiteral && importArgument.quasis.length === 1 && @@ -675,7 +675,7 @@ export default class Module { this.graph.warn(warning); } - private addDynamicImport(node: Import) { + private addDynamicImport(node: ImportExpression) { this.dynamicImports.push({ node, resolution: null }); } @@ -819,7 +819,7 @@ export default class Module { } } - private includeDynamicImport(node: Import) { + private includeDynamicImport(node: ImportExpression) { const resolution = (this.dynamicImports.find(dynamicImport => dynamicImport.node === node) as { resolution: string | Module | ExternalModule | undefined; }).resolution; diff --git a/src/ast/nodes/Import.ts b/src/ast/nodes/ImportExpression.ts similarity index 86% rename from src/ast/nodes/Import.ts rename to src/ast/nodes/ImportExpression.ts index b49074d90f4..08d6eaa4597 100644 --- a/src/ast/nodes/Import.ts +++ b/src/ast/nodes/ImportExpression.ts @@ -2,9 +2,8 @@ import MagicString from 'magic-string'; import { findFirstOccurrenceOutsideComment, RenderOptions } from '../../utils/renderHelpers'; import { INTEROP_NAMESPACE_VARIABLE } from '../../utils/variableNames'; import NamespaceVariable from '../variables/NamespaceVariable'; -import CallExpression from './CallExpression'; import * as NodeType from './NodeType'; -import { NodeBase } from './shared/Node'; +import { ExpressionNode, IncludeChildren, NodeBase } from './shared/Node'; interface DynamicImportMechanism { left: string; @@ -12,17 +11,22 @@ interface DynamicImportMechanism { } export default class Import extends NodeBase { - parent!: CallExpression; - type!: NodeType.tImport; + source!: ExpressionNode; + type!: NodeType.tImportExpression; private exportMode: 'none' | 'named' | 'default' | 'auto' = 'auto'; private inlineNamespace?: NamespaceVariable; - include() { + hasEffects(): boolean { + return true; + } + + include(includeChildrenRecursively: IncludeChildren) { if (!this.included) { this.included = true; this.context.includeDynamicImport(this); } + this.source.include(includeChildrenRecursively); } initialise() { @@ -34,8 +38,8 @@ export default class Import extends NodeBase { const _ = options.compact ? '' : ' '; const s = options.compact ? '' : ';'; code.overwrite( - this.parent.start, - this.parent.end, + this.start, + this.end, `Promise.resolve().then(function${_}()${_}{${_}return ${this.inlineNamespace.getName()}${s}${_}})` ); return; @@ -44,11 +48,11 @@ export default class Import extends NodeBase { const importMechanism = this.getDynamicImportMechanism(options); if (importMechanism) { code.overwrite( - this.parent.start, - findFirstOccurrenceOutsideComment(code.original, '(', this.parent.callee.end) + 1, + this.start, + findFirstOccurrenceOutsideComment(code.original, '(', this.start + 6) + 1, importMechanism.left ); - code.overwrite(this.parent.end - 1, this.parent.end, importMechanism.right); + code.overwrite(this.end - 1, this.end, importMechanism.right); } } @@ -57,7 +61,7 @@ export default class Import extends NodeBase { if (format === 'amd' && resolution.startsWith("'.") && resolution.endsWith(".js'")) { resolution = resolution.slice(0, -4) + "'"; } - code.overwrite(this.parent.arguments[0].start, this.parent.arguments[0].end, resolution); + code.overwrite(this.source.start, this.source.end, resolution); } } diff --git a/src/ast/nodes/MetaProperty.ts b/src/ast/nodes/MetaProperty.ts index 4c466ea7ffa..c30b1bc8566 100644 --- a/src/ast/nodes/MetaProperty.ts +++ b/src/ast/nodes/MetaProperty.ts @@ -19,6 +19,10 @@ export default class MetaProperty extends NodeBase { private metaProperty?: string | null; + hasEffects(): boolean { + return false; + } + hasEffectsWhenAccessedAtPath(path: ObjectPathKey[]): boolean { return path.length > 1; } diff --git a/src/ast/nodes/NodeType.ts b/src/ast/nodes/NodeType.ts index 26ca7bdfb55..74dc1950b69 100644 --- a/src/ast/nodes/NodeType.ts +++ b/src/ast/nodes/NodeType.ts @@ -29,6 +29,7 @@ export type tIdentifier = 'Identifier'; export type tIfStatement = 'IfStatement'; export type tImport = 'Import'; export type tImportDeclaration = 'ImportDeclaration'; +export type tImportExpression = 'ImportExpression'; export type tImportDefaultSpecifier = 'ImportDefaultSpecifier'; export type tImportNamespaceSpecifier = 'ImportNamespaceSpecifier'; export type tImportSpecifier = 'ImportSpecifier'; @@ -93,6 +94,7 @@ export const Identifier: tIdentifier = 'Identifier'; export const IfStatement: tIfStatement = 'IfStatement'; export const Import: tImport = 'Import'; export const ImportDeclaration: tImportDeclaration = 'ImportDeclaration'; +export const ImportExpression: tImportExpression = 'ImportExpression'; export const ImportDefaultSpecifier: tImportDefaultSpecifier = 'ImportDefaultSpecifier'; export const ImportNamespaceSpecifier: tImportNamespaceSpecifier = 'ImportNamespaceSpecifier'; export const ImportSpecifier: tImportSpecifier = 'ImportSpecifier'; diff --git a/src/ast/nodes/index.ts b/src/ast/nodes/index.ts index e2509ba0da2..6d629d152bb 100644 --- a/src/ast/nodes/index.ts +++ b/src/ast/nodes/index.ts @@ -26,8 +26,8 @@ import FunctionDeclaration from './FunctionDeclaration'; import FunctionExpression from './FunctionExpression'; import Identifier from './Identifier'; import IfStatement from './IfStatement'; -import Import from './Import'; import ImportDeclaration from './ImportDeclaration'; +import ImportExpression from './ImportExpression'; import LabeledStatement from './LabeledStatement'; import Literal from './Literal'; import LogicalExpression from './LogicalExpression'; @@ -91,8 +91,8 @@ export const nodeConstructors: { FunctionExpression, Identifier, IfStatement, - Import, ImportDeclaration, + ImportExpression, LabeledStatement, Literal, LogicalExpression, diff --git a/test/form/samples/new-target-meta-property/_config.js b/test/form/samples/new-target-meta-property/_config.js new file mode 100644 index 00000000000..0b9edf38046 --- /dev/null +++ b/test/form/samples/new-target-meta-property/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'supports the new.target meta property' +}; diff --git a/test/form/samples/new-target-meta-property/_expected.js b/test/form/samples/new-target-meta-property/_expected.js new file mode 100644 index 00000000000..27cb5cfe3ca --- /dev/null +++ b/test/form/samples/new-target-meta-property/_expected.js @@ -0,0 +1,7 @@ +class Foo { + constructor() { + console.log(new.target.name); + } +} + +const x = new Foo(); diff --git a/test/form/samples/new-target-meta-property/main.js b/test/form/samples/new-target-meta-property/main.js new file mode 100644 index 00000000000..2918a36d856 --- /dev/null +++ b/test/form/samples/new-target-meta-property/main.js @@ -0,0 +1,8 @@ +class Foo { + constructor() { + console.log(new.target.name); + const unused = new.target.name; + } +} + +const x = new Foo(); diff --git a/test/form/samples/supports-core-js/_expected.js b/test/form/samples/supports-core-js/_expected.js index de33bbc1079..63942917675 100644 --- a/test/form/samples/supports-core-js/_expected.js +++ b/test/form/samples/supports-core-js/_expected.js @@ -195,7 +195,7 @@ var store = global_1[SHARED] || setGlobal(SHARED, {}); (module.exports = function (key, value) { return store[key] || (store[key] = value !== undefined ? value : {}); })('versions', []).push({ - version: '3.1.3', + version: '3.2.1', mode: 'global', copyright: '© 2019 Denis Pushkarev (zloirock.ru)' }); @@ -4239,12 +4239,17 @@ var mathFround = Math.fround || function fround(x) { // https://tc39.github.io/ecma262/#sec-math.fround _export({ target: 'Math', stat: true }, { fround: mathFround }); +var $hypot = Math.hypot; var abs$4 = Math.abs; var sqrt$2 = Math.sqrt; +// Chrome 77 bug +// https://bugs.chromium.org/p/v8/issues/detail?id=9546 +var BUGGY = !!$hypot && $hypot(Infinity, NaN) !== Infinity; + // `Math.hypot` method // https://tc39.github.io/ecma262/#sec-math.hypot -_export({ target: 'Math', stat: true }, { +_export({ target: 'Math', stat: true, forced: BUGGY }, { hypot: function hypot(value1, value2) { // eslint-disable-line no-unused-vars var sum = 0; var i = 0; @@ -4456,6 +4461,8 @@ if (!(TO_PRIMITIVE$1 in DatePrototype$2)) hide(DatePrototype$2, TO_PRIMITIVE$1, // https://tc39.github.io/ecma262/#sec-json-@@tostringtag setToStringTag(global_1.JSON, 'JSON', true); +var nativePromiseConstructor = global_1.Promise; + var redefineAll = function (target, src, options) { for (var key in src) redefine(target, key, src[key], options); return target; @@ -4573,7 +4580,7 @@ var IS_NODE = classofRaw(process$1) == 'process'; var queueMicrotaskDescriptor = getOwnPropertyDescriptor$5(global_1, 'queueMicrotask'); var queueMicrotask = queueMicrotaskDescriptor && queueMicrotaskDescriptor.value; -var flush, head, last, notify, toggle, node, promise; +var flush, head, last, notify, toggle, node, promise, then; // modern engines have queueMicrotask method if (!queueMicrotask) { @@ -4611,8 +4618,9 @@ if (!queueMicrotask) { } else if (Promise && Promise.resolve) { // Promise.resolve without an argument throws an error in LG WebOS 2 promise = Promise.resolve(undefined); + then = promise.then; notify = function () { - promise.then(flush); + then.call(promise, flush); }; // for other environments - macrotask based on: // - setImmediate @@ -4697,7 +4705,7 @@ var PROMISE = 'Promise'; var getInternalState$4 = internalState.get; var setInternalState$4 = internalState.set; var getInternalPromiseState = internalState.getterFor(PROMISE); -var PromiseConstructor = global_1[PROMISE]; +var PromiseConstructor = nativePromiseConstructor; var TypeError$1 = global_1.TypeError; var document$2 = global_1.document; var process$2 = global_1.process; @@ -4715,7 +4723,7 @@ var FULFILLED = 1; var REJECTED = 2; var HANDLED = 1; var UNHANDLED = 2; -var Internal, OwnPromiseCapability, PromiseWrapper; +var Internal, OwnPromiseCapability, PromiseWrapper, nativeThen; var FORCED$e = isForced_1(PROMISE, function () { // correct subclassing with @@species support @@ -4940,13 +4948,25 @@ if (FORCED$e) { : newGenericPromiseCapability(C); }; - // wrap fetch result - if ( typeof $fetch == 'function') _export({ global: true, enumerable: true, forced: true }, { - // eslint-disable-next-line no-unused-vars - fetch: function fetch(input) { - return promiseResolve(PromiseConstructor, $fetch.apply(global_1, arguments)); - } - }); + if ( typeof nativePromiseConstructor == 'function') { + nativeThen = nativePromiseConstructor.prototype.then; + + // wrap native Promise#then for native async functions + redefine(nativePromiseConstructor.prototype, 'then', function then(onFulfilled, onRejected) { + var that = this; + return new PromiseConstructor(function (resolve, reject) { + nativeThen.call(that, resolve, reject); + }).then(onFulfilled, onRejected); + }); + + // wrap fetch result + if (typeof $fetch == 'function') _export({ global: true, enumerable: true, forced: true }, { + // eslint-disable-next-line no-unused-vars + fetch: function fetch(input) { + return promiseResolve(PromiseConstructor, $fetch.apply(global_1, arguments)); + } + }); + } } _export({ global: true, wrap: true, forced: FORCED$e }, { @@ -5024,6 +5044,43 @@ _export({ target: PROMISE, stat: true, forced: INCORRECT_ITERATION$1 }, { } }); +// `Promise.allSettled` method +// https://github.com/tc39/proposal-promise-allSettled +_export({ target: 'Promise', stat: true }, { + allSettled: function allSettled(iterable) { + var C = this; + var capability = newPromiseCapability.f(C); + var resolve = capability.resolve; + var reject = capability.reject; + var result = perform(function () { + var promiseResolve = aFunction$1(C.resolve); + var values = []; + var counter = 0; + var remaining = 1; + iterate_1(iterable, function (promise) { + var index = counter++; + var alreadyCalled = false; + values.push(undefined); + remaining++; + promiseResolve.call(C, promise).then(function (value) { + if (alreadyCalled) return; + alreadyCalled = true; + values[index] = { status: 'fulfilled', value: value }; + --remaining || resolve(values); + }, function (e) { + if (alreadyCalled) return; + alreadyCalled = true; + values[index] = { status: 'rejected', reason: e }; + --remaining || resolve(values); + }); + }); + --remaining || resolve(values); + }); + if (result.error) reject(result.value); + return capability.promise; + } +}); + // `Promise.prototype.finally` method // https://tc39.github.io/ecma262/#sec-promise.prototype.finally _export({ target: 'Promise', proto: true, real: true }, { @@ -5041,6 +5098,11 @@ _export({ target: 'Promise', proto: true, real: true }, { } }); +// patch native Promise.prototype for native async functions +if ( typeof nativePromiseConstructor == 'function' && !nativePromiseConstructor.prototype['finally']) { + redefine(nativePromiseConstructor.prototype, 'finally', getBuiltIn('Promise').prototype['finally']); +} + var collection = function (CONSTRUCTOR_NAME, wrapper, common, IS_MAP, IS_WEAK) { var NativeConstructor = global_1[CONSTRUCTOR_NAME]; var NativePrototype = NativeConstructor && NativeConstructor.prototype; @@ -5051,17 +5113,17 @@ var collection = function (CONSTRUCTOR_NAME, wrapper, common, IS_MAP, IS_WEAK) { var fixMethod = function (KEY) { var nativeMethod = NativePrototype[KEY]; redefine(NativePrototype, KEY, - KEY == 'add' ? function add(a) { - nativeMethod.call(this, a === 0 ? 0 : a); + KEY == 'add' ? function add(value) { + nativeMethod.call(this, value === 0 ? 0 : value); return this; - } : KEY == 'delete' ? function (a) { - return IS_WEAK && !isObject(a) ? false : nativeMethod.call(this, a === 0 ? 0 : a); - } : KEY == 'get' ? function get(a) { - return IS_WEAK && !isObject(a) ? undefined : nativeMethod.call(this, a === 0 ? 0 : a); - } : KEY == 'has' ? function has(a) { - return IS_WEAK && !isObject(a) ? false : nativeMethod.call(this, a === 0 ? 0 : a); - } : function set(a, b) { - nativeMethod.call(this, a === 0 ? 0 : a, b); + } : KEY == 'delete' ? function (key) { + return IS_WEAK && !isObject(key) ? false : nativeMethod.call(this, key === 0 ? 0 : key); + } : KEY == 'get' ? function get(key) { + return IS_WEAK && !isObject(key) ? undefined : nativeMethod.call(this, key === 0 ? 0 : key); + } : KEY == 'has' ? function has(key) { + return IS_WEAK && !isObject(key) ? false : nativeMethod.call(this, key === 0 ? 0 : key); + } : function set(key, value) { + nativeMethod.call(this, key === 0 ? 0 : key, value); return this; } ); @@ -5078,7 +5140,7 @@ var collection = function (CONSTRUCTOR_NAME, wrapper, common, IS_MAP, IS_WEAK) { var instance = new Constructor(); // early implementations not supports chaining var HASNT_CHAINING = instance[ADDER](IS_WEAK ? {} : -0, 1) != instance; - // V8 ~ Chromium 40- weak-collections throws on primitives, but should return false + // V8 ~ Chromium 40- weak-collections throws on primitives, but should return false var THROWS_ON_PRIMITIVES = fails(function () { instance.has(1); }); // most early implementations doesn't supports iterables, most modern - not close it correctly // eslint-disable-next-line no-new @@ -5538,7 +5600,8 @@ var isPrototypeOf = ObjectPrototype$3.isPrototypeOf; var TO_STRING_TAG$3 = wellKnownSymbol('toStringTag'); var TYPED_ARRAY_TAG = uid('TYPED_ARRAY_TAG'); var NATIVE_ARRAY_BUFFER = !!(global_1.ArrayBuffer && DataView); -var NATIVE_ARRAY_BUFFER_VIEWS = NATIVE_ARRAY_BUFFER && !!objectSetPrototypeOf; +// Fixing native typed arrays in Opera Presto crashes the browser, see #595 +var NATIVE_ARRAY_BUFFER_VIEWS = NATIVE_ARRAY_BUFFER && !!objectSetPrototypeOf && classof(global_1.opera) !== 'Opera'; var TYPED_ARRAY_TAG_REQIRED = false; var NAME$1; @@ -8798,8 +8861,10 @@ var collectionDeleteAll = function (/* ...elements */) { var collection = anObject(this); var remover = aFunction$1(collection['delete']); var allDeleted = true; + var wasDeleted; for (var k = 0, len = arguments.length; k < len; k++) { - allDeleted = allDeleted && remover.call(collection, arguments[k]); + wasDeleted = remover.call(collection, arguments[k]); + allDeleted = allDeleted && wasDeleted; } return !!allDeleted; }; @@ -9239,6 +9304,83 @@ _export({ target: 'WeakSet', stat: true }, { of: collectionOf }); +// TODO: in core-js@4, move /modules/ dependencies to public entries for better optimization by tools like `preset-env` + + + + + +var Node = function () { + // keys + this.object = null; + this.symbol = null; + // child nodes + this.primitives = null; + this.objectsByIndex = objectCreate(null); +}; + +Node.prototype.get = function (key, initializer) { + return this[key] || (this[key] = initializer()); +}; + +Node.prototype.next = function (i, it, IS_OBJECT) { + var store = IS_OBJECT + ? this.objectsByIndex[i] || (this.objectsByIndex[i] = new es_weakMap()) + : this.primitives || (this.primitives = new es_map()); + var entry = store.get(it); + if (!entry) store.set(it, entry = new Node()); + return entry; +}; + +var root = new Node(); + +var compositeKey = function () { + var active = root; + var length = arguments.length; + var i, it; + // for prevent leaking, start from objects + for (i = 0; i < length; i++) { + if (isObject(it = arguments[i])) active = active.next(i, it, true); + } + if (this === Object && active === root) throw TypeError('Composite keys must contain a non-primitive component'); + for (i = 0; i < length; i++) { + if (!isObject(it = arguments[i])) active = active.next(i, it, false); + } return active; +}; + +var initializer = function () { + var freeze = getBuiltIn('Object', 'freeze'); + return freeze ? freeze(objectCreate(null)) : objectCreate(null); +}; + +// https://github.com/tc39/proposal-richer-keys/tree/master/compositeKey +_export({ global: true }, { + compositeKey: function compositeKey$1() { + return compositeKey.apply(Object, arguments).get('object', initializer); + } +}); + +// https://github.com/tc39/proposal-richer-keys/tree/master/compositeKey +_export({ global: true }, { + compositeSymbol: function compositeSymbol() { + if (arguments.length === 1 && typeof arguments[0] === 'string') return getBuiltIn('Symbol')['for'](arguments[0]); + return compositeKey.apply(null, arguments).get('symbol', getBuiltIn('Symbol')); + } +}); + +// `Set.prototype.updateOrInsert` method +// https://docs.google.com/presentation/d/1_xtrGSoN1-l2Q74eCXPHBbbrBHsVyqArWN0ebnW-pVQ/ +_export({ target: 'Map', proto: true, real: true, forced: isPure }, { + updateOrInsert: function updateOrInsert(key, onUpdate, onInsert) { + var map = anObject(this); + aFunction$1(onUpdate); + aFunction$1(onInsert); + var value = map.has(key) ? onUpdate(map.get(key)) : onInsert(); + map.set(key, value); + return value; + } +}); + var min$9 = Math.min; var max$4 = Math.max; @@ -9574,70 +9716,6 @@ _export({ target: 'Promise', stat: true }, { } }); -// TODO: in core-js@4, move /modules/ dependencies to public entries for better optimization by tools like `preset-env` - - - - - -var Node = function () { - // keys - this.object = null; - this.symbol = null; - // child nodes - this.primitives = null; - this.objectsByIndex = objectCreate(null); -}; - -Node.prototype.get = function (key, initializer) { - return this[key] || (this[key] = initializer()); -}; - -Node.prototype.next = function (i, it, IS_OBJECT) { - var store = IS_OBJECT - ? this.objectsByIndex[i] || (this.objectsByIndex[i] = new es_weakMap()) - : this.primitives || (this.primitives = new es_map()); - var entry = store.get(it); - if (!entry) store.set(it, entry = new Node()); - return entry; -}; - -var root = new Node(); - -var compositeKey = function () { - var active = root; - var length = arguments.length; - var i, it; - // for prevent leaking, start from objects - for (i = 0; i < length; i++) { - if (isObject(it = arguments[i])) active = active.next(i, it, true); - } - if (this === Object && active === root) throw TypeError('Composite keys must contain a non-primitive component'); - for (i = 0; i < length; i++) { - if (!isObject(it = arguments[i])) active = active.next(i, it, false); - } return active; -}; - -var initializer = function () { - var freeze = getBuiltIn('Object', 'freeze'); - return freeze ? freeze(objectCreate(null)) : objectCreate(null); -}; - -// https://github.com/tc39/proposal-richer-keys/tree/master/compositeKey -_export({ global: true }, { - compositeKey: function compositeKey$1() { - return compositeKey.apply(Object, arguments).get('object', initializer); - } -}); - -// https://github.com/tc39/proposal-richer-keys/tree/master/compositeKey -_export({ global: true }, { - compositeSymbol: function compositeSymbol() { - if (arguments.length === 1 && typeof arguments[0] === 'string') return getBuiltIn('Symbol')['for'](arguments[0]); - return compositeKey.apply(null, arguments).get('symbol', getBuiltIn('Symbol')); - } -}); - var SEEDED_RANDOM = 'Seeded Random'; var SEEDED_RANDOM_GENERATOR = SEEDED_RANDOM + ' Generator'; var setInternalState$a = internalState.set; @@ -9698,9 +9776,31 @@ _export({ target: 'String', proto: true }, { } }); -// `Symbol.patternMatch` well-known symbol -// https://github.com/tc39/proposal-using-statement -defineWellKnownSymbol('dispose'); +var isFrozen = Object.isFrozen; + +var isFrozenStringArray = function (array, allowUndefined) { + if (!isFrozen || !isArray(array) || !isFrozen(array)) return false; + var index = 0; + var length = array.length; + var element; + while (index < length) { + element = array[index++]; + if (!(typeof element === 'string' || (allowUndefined && typeof element === 'undefined'))) { + return false; + } + } return length !== 0; +}; + +// `Array.isTemplateObject` method +// https://github.com/tc39/proposal-array-is-template-object +_export({ target: 'Array', stat: true }, { + isTemplateObject: function isTemplateObject(value) { + if (!isFrozenStringArray(value, true)) return false; + var raw = value.raw; + if (raw.length !== value.length || !isFrozenStringArray(raw, false)) return false; + return true; + } +}); var $AggregateError = function AggregateError(errors, message) { var that = this; @@ -9710,7 +9810,7 @@ var $AggregateError = function AggregateError(errors, message) { } var errorsArray = []; iterate_1(errors, errorsArray.push, errorsArray); - that.errors = errorsArray; + hide(that, 'errors', errorsArray); if (message !== undefined) hide(that, 'message', String(message)); return that; }; @@ -9904,49 +10004,20 @@ _export({ target: 'String', proto: true }, { // https://tc39.github.io/proposal-string-replaceall/ defineWellKnownSymbol('replaceAll'); +// `Symbol.asyncDispose` well-known symbol +// https://github.com/tc39/proposal-using-statement +defineWellKnownSymbol('asyncDispose'); + +// `Symbol.dispose` well-known symbol +// https://github.com/tc39/proposal-using-statement +defineWellKnownSymbol('dispose'); + // `globalThis` object // https://github.com/tc39/proposal-global _export({ global: true }, { globalThis: global_1 }); -// `Promise.allSettled` method -// https://github.com/tc39/proposal-promise-allSettled -_export({ target: 'Promise', stat: true }, { - allSettled: function allSettled(iterable) { - var C = this; - var capability = newPromiseCapability.f(C); - var resolve = capability.resolve; - var reject = capability.reject; - var result = perform(function () { - var promiseResolve = aFunction$1(C.resolve); - var values = []; - var counter = 0; - var remaining = 1; - iterate_1(iterable, function (promise) { - var index = counter++; - var alreadyCalled = false; - values.push(undefined); - remaining++; - promiseResolve.call(C, promise).then(function (value) { - if (alreadyCalled) return; - alreadyCalled = true; - values[index] = { status: 'fulfilled', value: value }; - --remaining || resolve(values); - }, function (e) { - if (alreadyCalled) return; - alreadyCalled = true; - values[index] = { status: 'rejected', reason: e }; - --remaining || resolve(values); - }); - }); - --remaining || resolve(values); - }); - if (result.error) reject(result.value); - return capability.promise; - } -}); - // iterable DOM collections // flag - `iterable` interface - 'entries', 'keys', 'values', 'forEach' methods var domIterables = {