diff --git a/node_modules/rollup/CHANGELOG.md b/node_modules/rollup/CHANGELOG.md index d4bab4088e..a554c8cd21 100644 --- a/node_modules/rollup/CHANGELOG.md +++ b/node_modules/rollup/CHANGELOG.md @@ -1,5 +1,108 @@ # rollup changelog +## 0.66.6 +*2018-10-10* +* Properly deconflict function and class declaration ids of reassigned default exports ([#2502](https://github.com/rollup/rollup/pull/2502)) + +## 0.66.5 +*2018-10-09* +* Remove cache from memory once no longer needed ([#2496](https://github.com/rollup/rollup/pull/2496)) +* Provide better error message when reexporting external namespace reexports ([#2499](https://github.com/rollup/rollup/pull/2499)) + +## 0.66.4 +*2018-10-04* +* Fix links in warnings and errors ([#2471](https://github.com/rollup/rollup/pull/2471)) + +## 0.66.3 +*2018-10-03* +* Detect side-effects in string.replace function arguments ([#2476](https://github.com/rollup/rollup/pull/2476)) +* Make sure chunk ids are assigned before creating output bundle ([#2483](https://github.com/rollup/rollup/pull/2483)) +* Use proper plugin name in error ([#2470](https://github.com/rollup/rollup/pull/2470)) +* Update TypeScript version and fix type errors ([#2488](https://github.com/rollup/rollup/pull/2488)) + +## 0.66.2 +*2018-09-21* +* Add additional information to parse errors messages in JSON and other non-JS files ([#2466](https://github.com/rollup/rollup/pull/2466)) + +## 0.66.1 +*2018-09-19* +* Ignore falsy plugins ([#2464](https://github.com/rollup/rollup/pull/2464)) +* Switch back to official TypeScript plugin ([#2465](https://github.com/rollup/rollup/pull/2465)) + +## 0.66.0 +*2018-09-16* +* Support ES2019 optional catch bindings ([#2455](https://github.com/rollup/rollup/pull/2455)) +* Add option to transform paths within sourcemaps ([#2430](https://github.com/rollup/rollup/pull/2430)) +* Add renderStart and renderEnd plugin hooks ([#2438](https://github.com/rollup/rollup/pull/2438)) +* Expose ESM browser build and minify browser builds ([#2437](https://github.com/rollup/rollup/pull/2437) +* Associate hoisted variables in function bodys with function parameters ([#2456](https://github.com/rollup/rollup/pull/2456)) +* Fix issue when deconflicting variables used as pattern defaults ([#2446](https://github.com/rollup/rollup/pull/2446)) +* Properly deconflict default exported class and function expressions with ids ([#2458](https://github.com/rollup/rollup/pull/2458)) +* Faster internal test builds ([#2457](https://github.com/rollup/rollup/pull/2457)) +* Switch to rollup-plugin-typescript2 ([#2460](https://github.com/rollup/rollup/pull/2460)) +* Fix internal "perf" script ([#2433](https://github.com/rollup/rollup/pull/2433)) +* Test that errors are passed to the buildEnd hook ([#2450](https://github.com/rollup/rollup/pull/2450)) + +## 0.65.2 +*2018-09-05* +* Prevent watch mode memory leak ([#2441](https://github.com/rollup/rollup/pull/2441)) + +## 0.65.1 +*2018-09-05* +* Prevent globbing when using chokidar ([#2432](https://github.com/rollup/rollup/pull/2432)) + +## 0.65.0 +*2018-08-25* +* Refactor and unify plugin system ([#2382](https://github.com/rollup/rollup/pull/2382)) +* Implement plugin cache API ([#2389](https://github.com/rollup/rollup/pull/2389)) +* Add watchChange plugin hook to watch changed files, deprecate asset dependencies ([#2405](https://github.com/rollup/rollup/pull/2405)) +* Refine asset handling ([#2369](https://github.com/rollup/rollup/pull/2369)) +* Implement `renderChunk` hook to replace `transformChunk` and `transformBundle` hooks ([#2406](https://github.com/rollup/rollup/pull/2406)) +* Add rollup version to plugin context ([#2394](https://github.com/rollup/rollup/pull/2394)) +* Do not resume stdin in watch mode to fix it for Lerna users ([#2410](https://github.com/rollup/rollup/pull/2410)) +* Allow `[format]` placeholder for id generation ([#2387](https://github.com/rollup/rollup/pull/2387)) +* Always log error stacks even when a code frame is given ([#2417](https://github.com/rollup/rollup/pull/2417)) +* Do not test module ids starting with `\0` as external ([#2400](https://github.com/rollup/rollup/pull/2400)) +* Fix tracing of namespace variables ([#2408](https://github.com/rollup/rollup/pull/2408)) +* Fix re-tracing of namespace variables ([#2420](https://github.com/rollup/rollup/pull/2420)) +* Properly wrap comment annotations in SystemJS exports ([#2408](https://github.com/rollup/rollup/pull/2408)) +* Fix renaming of destructured parameters ([#2419](https://github.com/rollup/rollup/pull/2419)) +* Do not display version in watch mode when using `--silent` ([#2392](https://github.com/rollup/rollup/pull/2392)) +* Make `cacheExpiry` an experimental option for now ([#2401](https://github.com/rollup/rollup/pull/2401)) +* Lint test configs on commit ([#2402](https://github.com/rollup/rollup/pull/2402)) +* Add code of conduct ([#2388](https://github.com/rollup/rollup/pull/2388)) +* Move to CircleCI ([#2390](https://github.com/rollup/rollup/pull/2390)) +* Update pull request template ([#2404](https://github.com/rollup/rollup/pull/2404)) + +## 0.64.1 +*2018-08-07* +* Do not render initializers of hoisted variables in dead branches ([#2384](https://github.com/rollup/rollup/pull/2384)) + +## 0.64.0 +*2018-08-07* +* Print memory consumption together with performance timings ([#2370](https://github.com/rollup/rollup/pull/2370)) +* Enable plugins to mark imports as external by returning false for resolveId ([#2351](https://github.com/rollup/rollup/pull/2351)) +* Always retain empty manual chunks ([#2362](https://github.com/rollup/rollup/pull/2362)) +* Ensure CLI warnings are shown on errors and add error for external id collisions ([#2334](https://github.com/rollup/rollup/pull/2334)) +* Remove unnecessary dependency, update dependencies, fix linting of test config ([#2376](https://github.com/rollup/rollup/pull/2376)) +* Add targeted Github issue templates ([#2356](https://github.com/rollup/rollup/pull/2356)) + +## 0.63.5 +*2018-08-01* +* Ensure onwrite plugin hooks execute in sequence ([#2364](https://github.com/rollup/rollup/pull/2364)) +* Always warn when no name is provided for a global module ([#2359](https://github.com/rollup/rollup/pull/2359)) +* Add utility type for user created plugins ([#2355](https://github.com/rollup/rollup/pull/2355)) +* Remove deprecated es6 format from types ([#2349](https://github.com/rollup/rollup/pull/2349)) +* Mark inlineDynamicImports as optional in types ([#2348](https://github.com/rollup/rollup/pull/2348)) + +## 0.63.4 +*2018-07-20* +* Use turbocolor instead of chalk ([#2339](https://github.com/rollup/rollup/pull/2339)) + +## 0.63.3 +*2018-07-20* +* Handle expressions where "in" and "instanceof" are applied to primitive values ([#2344](https://github.com/rollup/rollup/pull/2344)) + ## 0.63.2 *2018-07-18* * Fix bind order in for-of loops ([#2338](https://github.com/rollup/rollup/pull/2338)) diff --git a/node_modules/rollup/README.md b/node_modules/rollup/README.md index c292994f55..e020332c5a 100644 --- a/node_modules/rollup/README.md +++ b/node_modules/rollup/README.md @@ -109,11 +109,6 @@ Rollup can import existing CommonJS modules [through a plugin](https://github.co To make sure your ES modules are immediately usable by tools that work with CommonJS such as Node.js and webpack, you can use Rollup to compile to UMD or CommonJS format, and then point to that compiled version with the `main` property in your `package.json` file. If your `package.json` file also has a `module` field, ES-module-aware tools like Rollup and [webpack 2](https://webpack.js.org/) will [import the ES module version](https://github.com/rollup/rollup/wiki/pkg.module) directly. -## Links - -- step-by-step [tutorial video series](https://code.lengstorf.com/learn-rollup-js/), with accompanying written walkthrough -- miscellaneous issues in the [wiki](https://github.com/rollup/rollup/wiki) - ## Contributors This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. diff --git a/node_modules/rollup/bin/rollup b/node_modules/rollup/bin/rollup index 47662fd9ff..a0ed9bebe1 100755 --- a/node_modules/rollup/bin/rollup +++ b/node_modules/rollup/bin/rollup @@ -6,7 +6,6 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau var path = require('path'); var path__default = _interopDefault(path); var module$1 = _interopDefault(require('module')); -var os = _interopDefault(require('os')); var rollup = require('../dist/rollup.js'); var rollup__default = _interopDefault(rollup); var assert = _interopDefault(require('assert')); @@ -252,18 +251,32 @@ function isNumber (x) { return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x); } -var version = "0.63.2"; - -const __assign = Object.assign || function (target) { - for (var source, i = 1; i < arguments.length; i++) { - source = arguments[i]; - for (var prop in source) { - if (Object.prototype.hasOwnProperty.call(source, prop)) { - target[prop] = source[prop]; - } +var version = "0.66.6"; + +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + +var __assign = function() { + __assign = Object.assign || function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } - } - return target; + return t; + }; + return __assign.apply(this, arguments); }; function deprecateOptions(options, deprecateConfig) { @@ -374,14 +387,6 @@ function deprecateOptions(options, deprecateConfig) { } } -function ensureArray(thing) { - if (Array.isArray(thing)) - return thing; - if (thing == undefined) - return []; - return [thing]; -} - var createGetOption = function (config, command) { return function (name, defaultValue) { return command[name] !== undefined ? command[name] @@ -455,7 +460,8 @@ function mergeOptions(_a) { if (command.output) { Object.assign(command, command.output); } - var normalizedOutputOptions = ensureArray(config.output); + var output = config.output; + var normalizedOutputOptions = Array.isArray(output) ? output : output ? [output] : []; if (normalizedOutputOptions.length === 0) normalizedOutputOptions.push({}); var outputOptions = normalizedOutputOptions.map(function (singleOutputOptions) { @@ -466,7 +472,8 @@ function mergeOptions(_a) { addUnknownOptionErrors(unknownOptionErrors, Object.keys(config), validInputOptions, 'input option', /^output$/); var validOutputOptions = Object.keys(outputOptions[0]); addUnknownOptionErrors(unknownOptionErrors, outputOptions.reduce(function (allKeys, options) { return allKeys.concat(Object.keys(options)); }, []), validOutputOptions, 'output option'); - addUnknownOptionErrors(unknownOptionErrors, Object.keys(command), validInputOptions.concat(validOutputOptions, Object.keys(commandAliases), 'config', 'environment', 'silent'), 'CLI flag', /^_|output|(config.*)$/); + var validCliOutputOptions = validOutputOptions.filter(function (option) { return option !== 'sourcemapPathTransform'; }); + addUnknownOptionErrors(unknownOptionErrors, Object.keys(command), validInputOptions.concat(validCliOutputOptions, Object.keys(commandAliases), 'config', 'environment', 'silent'), 'CLI flag', /^_|output|(config.*)$/); return { inputOptions: inputOptions, outputOptions: outputOptions, @@ -503,6 +510,7 @@ function getInputOptions(config, command, defaultOnWarnHandler) { acorn: config.acorn, acornInjectPlugins: config.acornInjectPlugins, cache: getOption('cache'), + experimentalCacheExpiry: getOption('experimentalCacheExpiry', 10), context: config.context, experimentalCodeSplitting: getOption('experimentalCodeSplitting'), experimentalPreserveModules: getOption('experimentalPreserveModules'), @@ -536,2003 +544,190 @@ function getInputOptions(config, command, defaultOnWarnHandler) { else { inputOptions.entry = inputOptions.input; } - return inputOptions; -} -function getOutputOptions(config, command) { - if (command === void 0) { command = {}; } - var getOption = createGetOption(config, command); - var format = getOption('format'); - return { - amd: __assign({}, config.amd, command.amd), - assetFileNames: getOption('assetFileNames'), - banner: getOption('banner'), - dir: getOption('dir'), - chunkFileNames: getOption('chunkFileNames'), - compact: getOption('compact', false), - entryFileNames: getOption('entryFileNames'), - esModule: getOption('esModule', true), - exports: getOption('exports'), - extend: getOption('extend'), - file: getOption('file'), - footer: getOption('footer'), - format: format === 'esm' ? 'es' : format, - freeze: getOption('freeze', true), - globals: getOption('globals'), - indent: getOption('indent', true), - interop: getOption('interop', true), - intro: getOption('intro'), - name: getOption('name'), - namespaceToStringTag: getOption('namespaceToStringTag', false), - noConflict: getOption('noConflict'), - outro: getOption('outro'), - paths: getOption('paths'), - sourcemap: getOption('sourcemap'), - sourcemapFile: getOption('sourcemapFile'), - strict: getOption('strict', true) - }; -} -function deprecate(config, command, deprecateConfig) { - if (command === void 0) { command = {}; } - if (deprecateConfig === void 0) { deprecateConfig = { input: true, output: true }; } - var deprecations = []; - // CLI - if (command.id) { - deprecations.push({ - old: '-u/--id', - new: '--amd.id' - }); - (command.amd || (command.amd = {})).id = command.id; - } - if (typeof command.output === 'string') { - deprecations.push({ - old: '--output', - new: '--file' - }); - command.output = { file: command.output }; - } - if (command.d) { - deprecations.push({ - old: '-d', - new: '--indent' - }); - command.indent = command.d; - } - // config file - deprecations.push.apply(deprecations, deprecateOptions(config, deprecateConfig)); - return deprecations; -} - -var modules = {}; - -var getModule = function(dir) { - var rootPath = dir ? path__default.resolve(dir) : process.cwd(); - var rootName = path__default.join(rootPath, '@root'); - var root = modules[rootName]; - if (!root) { - root = new module$1(rootName); - root.filename = rootName; - root.paths = module$1._nodeModulePaths(rootPath); - modules[rootName] = root; - } - return root; -}; - -var requireRelative = function(requested, relativeTo) { - var root = getModule(relativeTo); - return root.require(requested); -}; - -requireRelative.resolve = function(requested, relativeTo) { - var root = getModule(relativeTo); - return module$1._resolveFilename(requested, root); -}; - -var requireRelative_1 = requireRelative; - -var absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/; -function isAbsolute(path$$1) { - return absolutePath.test(path$$1); -} - -function getAliasName(resolved, unresolved) { - var alias = path.basename(unresolved || resolved); - var ext = path.extname(resolved); - if (alias.endsWith(ext)) - alias = alias.substr(0, alias.length - ext.length); - return alias; -} -function relativeId(id) { - if (typeof process === 'undefined' || !isAbsolute(id)) - return id; - return path.relative(process.cwd(), id); -} - -function createCommonjsModule(fn, module) { - return module = { exports: {} }, fn(module, module.exports), module.exports; -} - -var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g; - -var escapeStringRegexp = function (str) { - if (typeof str !== 'string') { - throw new TypeError('Expected a string'); - } - - return str.replace(matchOperatorsRe, '\\$&'); -}; - -var colorName = { - "aliceblue": [240, 248, 255], - "antiquewhite": [250, 235, 215], - "aqua": [0, 255, 255], - "aquamarine": [127, 255, 212], - "azure": [240, 255, 255], - "beige": [245, 245, 220], - "bisque": [255, 228, 196], - "black": [0, 0, 0], - "blanchedalmond": [255, 235, 205], - "blue": [0, 0, 255], - "blueviolet": [138, 43, 226], - "brown": [165, 42, 42], - "burlywood": [222, 184, 135], - "cadetblue": [95, 158, 160], - "chartreuse": [127, 255, 0], - "chocolate": [210, 105, 30], - "coral": [255, 127, 80], - "cornflowerblue": [100, 149, 237], - "cornsilk": [255, 248, 220], - "crimson": [220, 20, 60], - "cyan": [0, 255, 255], - "darkblue": [0, 0, 139], - "darkcyan": [0, 139, 139], - "darkgoldenrod": [184, 134, 11], - "darkgray": [169, 169, 169], - "darkgreen": [0, 100, 0], - "darkgrey": [169, 169, 169], - "darkkhaki": [189, 183, 107], - "darkmagenta": [139, 0, 139], - "darkolivegreen": [85, 107, 47], - "darkorange": [255, 140, 0], - "darkorchid": [153, 50, 204], - "darkred": [139, 0, 0], - "darksalmon": [233, 150, 122], - "darkseagreen": [143, 188, 143], - "darkslateblue": [72, 61, 139], - "darkslategray": [47, 79, 79], - "darkslategrey": [47, 79, 79], - "darkturquoise": [0, 206, 209], - "darkviolet": [148, 0, 211], - "deeppink": [255, 20, 147], - "deepskyblue": [0, 191, 255], - "dimgray": [105, 105, 105], - "dimgrey": [105, 105, 105], - "dodgerblue": [30, 144, 255], - "firebrick": [178, 34, 34], - "floralwhite": [255, 250, 240], - "forestgreen": [34, 139, 34], - "fuchsia": [255, 0, 255], - "gainsboro": [220, 220, 220], - "ghostwhite": [248, 248, 255], - "gold": [255, 215, 0], - "goldenrod": [218, 165, 32], - "gray": [128, 128, 128], - "green": [0, 128, 0], - "greenyellow": [173, 255, 47], - "grey": [128, 128, 128], - "honeydew": [240, 255, 240], - "hotpink": [255, 105, 180], - "indianred": [205, 92, 92], - "indigo": [75, 0, 130], - "ivory": [255, 255, 240], - "khaki": [240, 230, 140], - "lavender": [230, 230, 250], - "lavenderblush": [255, 240, 245], - "lawngreen": [124, 252, 0], - "lemonchiffon": [255, 250, 205], - "lightblue": [173, 216, 230], - "lightcoral": [240, 128, 128], - "lightcyan": [224, 255, 255], - "lightgoldenrodyellow": [250, 250, 210], - "lightgray": [211, 211, 211], - "lightgreen": [144, 238, 144], - "lightgrey": [211, 211, 211], - "lightpink": [255, 182, 193], - "lightsalmon": [255, 160, 122], - "lightseagreen": [32, 178, 170], - "lightskyblue": [135, 206, 250], - "lightslategray": [119, 136, 153], - "lightslategrey": [119, 136, 153], - "lightsteelblue": [176, 196, 222], - "lightyellow": [255, 255, 224], - "lime": [0, 255, 0], - "limegreen": [50, 205, 50], - "linen": [250, 240, 230], - "magenta": [255, 0, 255], - "maroon": [128, 0, 0], - "mediumaquamarine": [102, 205, 170], - "mediumblue": [0, 0, 205], - "mediumorchid": [186, 85, 211], - "mediumpurple": [147, 112, 219], - "mediumseagreen": [60, 179, 113], - "mediumslateblue": [123, 104, 238], - "mediumspringgreen": [0, 250, 154], - "mediumturquoise": [72, 209, 204], - "mediumvioletred": [199, 21, 133], - "midnightblue": [25, 25, 112], - "mintcream": [245, 255, 250], - "mistyrose": [255, 228, 225], - "moccasin": [255, 228, 181], - "navajowhite": [255, 222, 173], - "navy": [0, 0, 128], - "oldlace": [253, 245, 230], - "olive": [128, 128, 0], - "olivedrab": [107, 142, 35], - "orange": [255, 165, 0], - "orangered": [255, 69, 0], - "orchid": [218, 112, 214], - "palegoldenrod": [238, 232, 170], - "palegreen": [152, 251, 152], - "paleturquoise": [175, 238, 238], - "palevioletred": [219, 112, 147], - "papayawhip": [255, 239, 213], - "peachpuff": [255, 218, 185], - "peru": [205, 133, 63], - "pink": [255, 192, 203], - "plum": [221, 160, 221], - "powderblue": [176, 224, 230], - "purple": [128, 0, 128], - "rebeccapurple": [102, 51, 153], - "red": [255, 0, 0], - "rosybrown": [188, 143, 143], - "royalblue": [65, 105, 225], - "saddlebrown": [139, 69, 19], - "salmon": [250, 128, 114], - "sandybrown": [244, 164, 96], - "seagreen": [46, 139, 87], - "seashell": [255, 245, 238], - "sienna": [160, 82, 45], - "silver": [192, 192, 192], - "skyblue": [135, 206, 235], - "slateblue": [106, 90, 205], - "slategray": [112, 128, 144], - "slategrey": [112, 128, 144], - "snow": [255, 250, 250], - "springgreen": [0, 255, 127], - "steelblue": [70, 130, 180], - "tan": [210, 180, 140], - "teal": [0, 128, 128], - "thistle": [216, 191, 216], - "tomato": [255, 99, 71], - "turquoise": [64, 224, 208], - "violet": [238, 130, 238], - "wheat": [245, 222, 179], - "white": [255, 255, 255], - "whitesmoke": [245, 245, 245], - "yellow": [255, 255, 0], - "yellowgreen": [154, 205, 50] -}; - -var conversions = createCommonjsModule(function (module) { -/* MIT license */ - - -// NOTE: conversions should only return primitive values (i.e. arrays, or -// values that give correct `typeof` results). -// do not use box values types (i.e. Number(), String(), etc.) - -var reverseKeywords = {}; -for (var key in colorName) { - if (colorName.hasOwnProperty(key)) { - reverseKeywords[colorName[key]] = key; - } -} - -var convert = module.exports = { - rgb: {channels: 3, labels: 'rgb'}, - hsl: {channels: 3, labels: 'hsl'}, - hsv: {channels: 3, labels: 'hsv'}, - hwb: {channels: 3, labels: 'hwb'}, - cmyk: {channels: 4, labels: 'cmyk'}, - xyz: {channels: 3, labels: 'xyz'}, - lab: {channels: 3, labels: 'lab'}, - lch: {channels: 3, labels: 'lch'}, - hex: {channels: 1, labels: ['hex']}, - keyword: {channels: 1, labels: ['keyword']}, - ansi16: {channels: 1, labels: ['ansi16']}, - ansi256: {channels: 1, labels: ['ansi256']}, - hcg: {channels: 3, labels: ['h', 'c', 'g']}, - apple: {channels: 3, labels: ['r16', 'g16', 'b16']}, - gray: {channels: 1, labels: ['gray']} -}; - -// hide .channels and .labels properties -for (var model in convert) { - if (convert.hasOwnProperty(model)) { - if (!('channels' in convert[model])) { - throw new Error('missing channels property: ' + model); - } - - if (!('labels' in convert[model])) { - throw new Error('missing channel labels property: ' + model); - } - - if (convert[model].labels.length !== convert[model].channels) { - throw new Error('channel and label counts mismatch: ' + model); - } - - var channels = convert[model].channels; - var labels = convert[model].labels; - delete convert[model].channels; - delete convert[model].labels; - Object.defineProperty(convert[model], 'channels', {value: channels}); - Object.defineProperty(convert[model], 'labels', {value: labels}); - } -} - -convert.rgb.hsl = function (rgb) { - var r = rgb[0] / 255; - var g = rgb[1] / 255; - var b = rgb[2] / 255; - var min = Math.min(r, g, b); - var max = Math.max(r, g, b); - var delta = max - min; - var h; - var s; - var l; - - if (max === min) { - h = 0; - } else if (r === max) { - h = (g - b) / delta; - } else if (g === max) { - h = 2 + (b - r) / delta; - } else if (b === max) { - h = 4 + (r - g) / delta; - } - - h = Math.min(h * 60, 360); - - if (h < 0) { - h += 360; - } - - l = (min + max) / 2; - - if (max === min) { - s = 0; - } else if (l <= 0.5) { - s = delta / (max + min); - } else { - s = delta / (2 - max - min); - } - - return [h, s * 100, l * 100]; -}; - -convert.rgb.hsv = function (rgb) { - var rdif; - var gdif; - var bdif; - var h; - var s; - - var r = rgb[0] / 255; - var g = rgb[1] / 255; - var b = rgb[2] / 255; - var v = Math.max(r, g, b); - var diff = v - Math.min(r, g, b); - var diffc = function (c) { - return (v - c) / 6 / diff + 1 / 2; - }; - - if (diff === 0) { - h = s = 0; - } else { - s = diff / v; - rdif = diffc(r); - gdif = diffc(g); - bdif = diffc(b); - - if (r === v) { - h = bdif - gdif; - } else if (g === v) { - h = (1 / 3) + rdif - bdif; - } else if (b === v) { - h = (2 / 3) + gdif - rdif; - } - if (h < 0) { - h += 1; - } else if (h > 1) { - h -= 1; - } - } - - return [ - h * 360, - s * 100, - v * 100 - ]; -}; - -convert.rgb.hwb = function (rgb) { - var r = rgb[0]; - var g = rgb[1]; - var b = rgb[2]; - var h = convert.rgb.hsl(rgb)[0]; - var w = 1 / 255 * Math.min(r, Math.min(g, b)); - - b = 1 - 1 / 255 * Math.max(r, Math.max(g, b)); - - return [h, w * 100, b * 100]; -}; - -convert.rgb.cmyk = function (rgb) { - var r = rgb[0] / 255; - var g = rgb[1] / 255; - var b = rgb[2] / 255; - var c; - var m; - var y; - var k; - - k = Math.min(1 - r, 1 - g, 1 - b); - c = (1 - r - k) / (1 - k) || 0; - m = (1 - g - k) / (1 - k) || 0; - y = (1 - b - k) / (1 - k) || 0; - - return [c * 100, m * 100, y * 100, k * 100]; -}; - -/** - * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance - * */ -function comparativeDistance(x, y) { - return ( - Math.pow(x[0] - y[0], 2) + - Math.pow(x[1] - y[1], 2) + - Math.pow(x[2] - y[2], 2) - ); -} - -convert.rgb.keyword = function (rgb) { - var reversed = reverseKeywords[rgb]; - if (reversed) { - return reversed; - } - - var currentClosestDistance = Infinity; - var currentClosestKeyword; - - for (var keyword in colorName) { - if (colorName.hasOwnProperty(keyword)) { - var value = colorName[keyword]; - - // Compute comparative distance - var distance = comparativeDistance(rgb, value); - - // Check if its less, if so set as closest - if (distance < currentClosestDistance) { - currentClosestDistance = distance; - currentClosestKeyword = keyword; - } - } - } - - return currentClosestKeyword; -}; - -convert.keyword.rgb = function (keyword) { - return colorName[keyword]; -}; - -convert.rgb.xyz = function (rgb) { - var r = rgb[0] / 255; - var g = rgb[1] / 255; - var b = rgb[2] / 255; - - // assume sRGB - r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92); - g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92); - b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92); - - var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805); - var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722); - var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505); - - return [x * 100, y * 100, z * 100]; -}; - -convert.rgb.lab = function (rgb) { - var xyz = convert.rgb.xyz(rgb); - var x = xyz[0]; - var y = xyz[1]; - var z = xyz[2]; - var l; - var a; - var b; - - x /= 95.047; - y /= 100; - z /= 108.883; - - x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116); - y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116); - z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116); - - l = (116 * y) - 16; - a = 500 * (x - y); - b = 200 * (y - z); - - return [l, a, b]; -}; - -convert.hsl.rgb = function (hsl) { - var h = hsl[0] / 360; - var s = hsl[1] / 100; - var l = hsl[2] / 100; - var t1; - var t2; - var t3; - var rgb; - var val; - - if (s === 0) { - val = l * 255; - return [val, val, val]; - } - - if (l < 0.5) { - t2 = l * (1 + s); - } else { - t2 = l + s - l * s; - } - - t1 = 2 * l - t2; - - rgb = [0, 0, 0]; - for (var i = 0; i < 3; i++) { - t3 = h + 1 / 3 * -(i - 1); - if (t3 < 0) { - t3++; - } - if (t3 > 1) { - t3--; - } - - if (6 * t3 < 1) { - val = t1 + (t2 - t1) * 6 * t3; - } else if (2 * t3 < 1) { - val = t2; - } else if (3 * t3 < 2) { - val = t1 + (t2 - t1) * (2 / 3 - t3) * 6; - } else { - val = t1; - } - - rgb[i] = val * 255; - } - - return rgb; -}; - -convert.hsl.hsv = function (hsl) { - var h = hsl[0]; - var s = hsl[1] / 100; - var l = hsl[2] / 100; - var smin = s; - var lmin = Math.max(l, 0.01); - var sv; - var v; - - l *= 2; - s *= (l <= 1) ? l : 2 - l; - smin *= lmin <= 1 ? lmin : 2 - lmin; - v = (l + s) / 2; - sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s); - - return [h, sv * 100, v * 100]; -}; - -convert.hsv.rgb = function (hsv) { - var h = hsv[0] / 60; - var s = hsv[1] / 100; - var v = hsv[2] / 100; - var hi = Math.floor(h) % 6; - - var f = h - Math.floor(h); - var p = 255 * v * (1 - s); - var q = 255 * v * (1 - (s * f)); - var t = 255 * v * (1 - (s * (1 - f))); - v *= 255; - - switch (hi) { - case 0: - return [v, t, p]; - case 1: - return [q, v, p]; - case 2: - return [p, v, t]; - case 3: - return [p, q, v]; - case 4: - return [t, p, v]; - case 5: - return [v, p, q]; - } -}; - -convert.hsv.hsl = function (hsv) { - var h = hsv[0]; - var s = hsv[1] / 100; - var v = hsv[2] / 100; - var vmin = Math.max(v, 0.01); - var lmin; - var sl; - var l; - - l = (2 - s) * v; - lmin = (2 - s) * vmin; - sl = s * vmin; - sl /= (lmin <= 1) ? lmin : 2 - lmin; - sl = sl || 0; - l /= 2; - - return [h, sl * 100, l * 100]; -}; - -// http://dev.w3.org/csswg/css-color/#hwb-to-rgb -convert.hwb.rgb = function (hwb) { - var h = hwb[0] / 360; - var wh = hwb[1] / 100; - var bl = hwb[2] / 100; - var ratio = wh + bl; - var i; - var v; - var f; - var n; - - // wh + bl cant be > 1 - if (ratio > 1) { - wh /= ratio; - bl /= ratio; - } - - i = Math.floor(6 * h); - v = 1 - bl; - f = 6 * h - i; - - if ((i & 0x01) !== 0) { - f = 1 - f; - } - - n = wh + f * (v - wh); // linear interpolation - - var r; - var g; - var b; - switch (i) { - default: - case 6: - case 0: r = v; g = n; b = wh; break; - case 1: r = n; g = v; b = wh; break; - case 2: r = wh; g = v; b = n; break; - case 3: r = wh; g = n; b = v; break; - case 4: r = n; g = wh; b = v; break; - case 5: r = v; g = wh; b = n; break; - } - - return [r * 255, g * 255, b * 255]; -}; - -convert.cmyk.rgb = function (cmyk) { - var c = cmyk[0] / 100; - var m = cmyk[1] / 100; - var y = cmyk[2] / 100; - var k = cmyk[3] / 100; - var r; - var g; - var b; - - r = 1 - Math.min(1, c * (1 - k) + k); - g = 1 - Math.min(1, m * (1 - k) + k); - b = 1 - Math.min(1, y * (1 - k) + k); - - return [r * 255, g * 255, b * 255]; -}; - -convert.xyz.rgb = function (xyz) { - var x = xyz[0] / 100; - var y = xyz[1] / 100; - var z = xyz[2] / 100; - var r; - var g; - var b; - - r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986); - g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415); - b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570); - - // assume sRGB - r = r > 0.0031308 - ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055) - : r * 12.92; - - g = g > 0.0031308 - ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055) - : g * 12.92; - - b = b > 0.0031308 - ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055) - : b * 12.92; - - r = Math.min(Math.max(0, r), 1); - g = Math.min(Math.max(0, g), 1); - b = Math.min(Math.max(0, b), 1); - - return [r * 255, g * 255, b * 255]; -}; - -convert.xyz.lab = function (xyz) { - var x = xyz[0]; - var y = xyz[1]; - var z = xyz[2]; - var l; - var a; - var b; - - x /= 95.047; - y /= 100; - z /= 108.883; - - x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116); - y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116); - z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116); - - l = (116 * y) - 16; - a = 500 * (x - y); - b = 200 * (y - z); - - return [l, a, b]; -}; - -convert.lab.xyz = function (lab) { - var l = lab[0]; - var a = lab[1]; - var b = lab[2]; - var x; - var y; - var z; - - y = (l + 16) / 116; - x = a / 500 + y; - z = y - b / 200; - - var y2 = Math.pow(y, 3); - var x2 = Math.pow(x, 3); - var z2 = Math.pow(z, 3); - y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787; - x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787; - z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787; - - x *= 95.047; - y *= 100; - z *= 108.883; - - return [x, y, z]; -}; - -convert.lab.lch = function (lab) { - var l = lab[0]; - var a = lab[1]; - var b = lab[2]; - var hr; - var h; - var c; - - hr = Math.atan2(b, a); - h = hr * 360 / 2 / Math.PI; - - if (h < 0) { - h += 360; - } - - c = Math.sqrt(a * a + b * b); - - return [l, c, h]; -}; - -convert.lch.lab = function (lch) { - var l = lch[0]; - var c = lch[1]; - var h = lch[2]; - var a; - var b; - var hr; - - hr = h / 360 * 2 * Math.PI; - a = c * Math.cos(hr); - b = c * Math.sin(hr); - - return [l, a, b]; -}; - -convert.rgb.ansi16 = function (args) { - var r = args[0]; - var g = args[1]; - var b = args[2]; - var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization - - value = Math.round(value / 50); - - if (value === 0) { - return 30; - } - - var ansi = 30 - + ((Math.round(b / 255) << 2) - | (Math.round(g / 255) << 1) - | Math.round(r / 255)); - - if (value === 2) { - ansi += 60; - } - - return ansi; -}; - -convert.hsv.ansi16 = function (args) { - // optimization here; we already know the value and don't need to get - // it converted for us. - return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]); -}; - -convert.rgb.ansi256 = function (args) { - var r = args[0]; - var g = args[1]; - var b = args[2]; - - // we use the extended greyscale palette here, with the exception of - // black and white. normal palette only has 4 greyscale shades. - if (r === g && g === b) { - if (r < 8) { - return 16; - } - - if (r > 248) { - return 231; - } - - return Math.round(((r - 8) / 247) * 24) + 232; - } - - var ansi = 16 - + (36 * Math.round(r / 255 * 5)) - + (6 * Math.round(g / 255 * 5)) - + Math.round(b / 255 * 5); - - return ansi; -}; - -convert.ansi16.rgb = function (args) { - var color = args % 10; - - // handle greyscale - if (color === 0 || color === 7) { - if (args > 50) { - color += 3.5; - } - - color = color / 10.5 * 255; - - return [color, color, color]; - } - - var mult = (~~(args > 50) + 1) * 0.5; - var r = ((color & 1) * mult) * 255; - var g = (((color >> 1) & 1) * mult) * 255; - var b = (((color >> 2) & 1) * mult) * 255; - - return [r, g, b]; -}; - -convert.ansi256.rgb = function (args) { - // handle greyscale - if (args >= 232) { - var c = (args - 232) * 10 + 8; - return [c, c, c]; - } - - args -= 16; - - var rem; - var r = Math.floor(args / 36) / 5 * 255; - var g = Math.floor((rem = args % 36) / 6) / 5 * 255; - var b = (rem % 6) / 5 * 255; - - return [r, g, b]; -}; - -convert.rgb.hex = function (args) { - var integer = ((Math.round(args[0]) & 0xFF) << 16) - + ((Math.round(args[1]) & 0xFF) << 8) - + (Math.round(args[2]) & 0xFF); - - var string = integer.toString(16).toUpperCase(); - return '000000'.substring(string.length) + string; -}; - -convert.hex.rgb = function (args) { - var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i); - if (!match) { - return [0, 0, 0]; - } - - var colorString = match[0]; - - if (match[0].length === 3) { - colorString = colorString.split('').map(function (char) { - return char + char; - }).join(''); - } - - var integer = parseInt(colorString, 16); - var r = (integer >> 16) & 0xFF; - var g = (integer >> 8) & 0xFF; - var b = integer & 0xFF; - - return [r, g, b]; -}; - -convert.rgb.hcg = function (rgb) { - var r = rgb[0] / 255; - var g = rgb[1] / 255; - var b = rgb[2] / 255; - var max = Math.max(Math.max(r, g), b); - var min = Math.min(Math.min(r, g), b); - var chroma = (max - min); - var grayscale; - var hue; - - if (chroma < 1) { - grayscale = min / (1 - chroma); - } else { - grayscale = 0; - } - - if (chroma <= 0) { - hue = 0; - } else - if (max === r) { - hue = ((g - b) / chroma) % 6; - } else - if (max === g) { - hue = 2 + (b - r) / chroma; - } else { - hue = 4 + (r - g) / chroma + 4; - } - - hue /= 6; - hue %= 1; - - return [hue * 360, chroma * 100, grayscale * 100]; -}; - -convert.hsl.hcg = function (hsl) { - var s = hsl[1] / 100; - var l = hsl[2] / 100; - var c = 1; - var f = 0; - - if (l < 0.5) { - c = 2.0 * s * l; - } else { - c = 2.0 * s * (1.0 - l); - } - - if (c < 1.0) { - f = (l - 0.5 * c) / (1.0 - c); - } - - return [hsl[0], c * 100, f * 100]; -}; - -convert.hsv.hcg = function (hsv) { - var s = hsv[1] / 100; - var v = hsv[2] / 100; - - var c = s * v; - var f = 0; - - if (c < 1.0) { - f = (v - c) / (1 - c); - } - - return [hsv[0], c * 100, f * 100]; -}; - -convert.hcg.rgb = function (hcg) { - var h = hcg[0] / 360; - var c = hcg[1] / 100; - var g = hcg[2] / 100; - - if (c === 0.0) { - return [g * 255, g * 255, g * 255]; - } - - var pure = [0, 0, 0]; - var hi = (h % 1) * 6; - var v = hi % 1; - var w = 1 - v; - var mg = 0; - - switch (Math.floor(hi)) { - case 0: - pure[0] = 1; pure[1] = v; pure[2] = 0; break; - case 1: - pure[0] = w; pure[1] = 1; pure[2] = 0; break; - case 2: - pure[0] = 0; pure[1] = 1; pure[2] = v; break; - case 3: - pure[0] = 0; pure[1] = w; pure[2] = 1; break; - case 4: - pure[0] = v; pure[1] = 0; pure[2] = 1; break; - default: - pure[0] = 1; pure[1] = 0; pure[2] = w; - } - - mg = (1.0 - c) * g; - - return [ - (c * pure[0] + mg) * 255, - (c * pure[1] + mg) * 255, - (c * pure[2] + mg) * 255 - ]; -}; - -convert.hcg.hsv = function (hcg) { - var c = hcg[1] / 100; - var g = hcg[2] / 100; - - var v = c + g * (1.0 - c); - var f = 0; - - if (v > 0.0) { - f = c / v; - } - - return [hcg[0], f * 100, v * 100]; -}; - -convert.hcg.hsl = function (hcg) { - var c = hcg[1] / 100; - var g = hcg[2] / 100; - - var l = g * (1.0 - c) + 0.5 * c; - var s = 0; - - if (l > 0.0 && l < 0.5) { - s = c / (2 * l); - } else - if (l >= 0.5 && l < 1.0) { - s = c / (2 * (1 - l)); - } - - return [hcg[0], s * 100, l * 100]; -}; - -convert.hcg.hwb = function (hcg) { - var c = hcg[1] / 100; - var g = hcg[2] / 100; - var v = c + g * (1.0 - c); - return [hcg[0], (v - c) * 100, (1 - v) * 100]; -}; - -convert.hwb.hcg = function (hwb) { - var w = hwb[1] / 100; - var b = hwb[2] / 100; - var v = 1 - b; - var c = v - w; - var g = 0; - - if (c < 1) { - g = (v - c) / (1 - c); - } - - return [hwb[0], c * 100, g * 100]; -}; - -convert.apple.rgb = function (apple) { - return [(apple[0] / 65535) * 255, (apple[1] / 65535) * 255, (apple[2] / 65535) * 255]; -}; - -convert.rgb.apple = function (rgb) { - return [(rgb[0] / 255) * 65535, (rgb[1] / 255) * 65535, (rgb[2] / 255) * 65535]; -}; - -convert.gray.rgb = function (args) { - return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255]; -}; - -convert.gray.hsl = convert.gray.hsv = function (args) { - return [0, 0, args[0]]; -}; - -convert.gray.hwb = function (gray) { - return [0, 100, gray[0]]; -}; - -convert.gray.cmyk = function (gray) { - return [0, 0, 0, gray[0]]; -}; - -convert.gray.lab = function (gray) { - return [gray[0], 0, 0]; -}; - -convert.gray.hex = function (gray) { - var val = Math.round(gray[0] / 100 * 255) & 0xFF; - var integer = (val << 16) + (val << 8) + val; - - var string = integer.toString(16).toUpperCase(); - return '000000'.substring(string.length) + string; -}; - -convert.rgb.gray = function (rgb) { - var val = (rgb[0] + rgb[1] + rgb[2]) / 3; - return [val / 255 * 100]; -}; -}); -var conversions_1 = conversions.rgb; -var conversions_2 = conversions.hsl; -var conversions_3 = conversions.hsv; -var conversions_4 = conversions.hwb; -var conversions_5 = conversions.cmyk; -var conversions_6 = conversions.xyz; -var conversions_7 = conversions.lab; -var conversions_8 = conversions.lch; -var conversions_9 = conversions.hex; -var conversions_10 = conversions.keyword; -var conversions_11 = conversions.ansi16; -var conversions_12 = conversions.ansi256; -var conversions_13 = conversions.hcg; -var conversions_14 = conversions.apple; -var conversions_15 = conversions.gray; - -/* - this function routes a model to all other models. - - all functions that are routed have a property `.conversion` attached - to the returned synthetic function. This property is an array - of strings, each with the steps in between the 'from' and 'to' - color models (inclusive). - - conversions that are not possible simply are not included. -*/ - -function buildGraph() { - var graph = {}; - // https://jsperf.com/object-keys-vs-for-in-with-closure/3 - var models = Object.keys(conversions); - - for (var len = models.length, i = 0; i < len; i++) { - graph[models[i]] = { - // http://jsperf.com/1-vs-infinity - // micro-opt, but this is simple. - distance: -1, - parent: null - }; - } - - return graph; -} - -// https://en.wikipedia.org/wiki/Breadth-first_search -function deriveBFS(fromModel) { - var graph = buildGraph(); - var queue = [fromModel]; // unshift -> queue -> pop - - graph[fromModel].distance = 0; - - while (queue.length) { - var current = queue.pop(); - var adjacents = Object.keys(conversions[current]); - - for (var len = adjacents.length, i = 0; i < len; i++) { - var adjacent = adjacents[i]; - var node = graph[adjacent]; - - if (node.distance === -1) { - node.distance = graph[current].distance + 1; - node.parent = current; - queue.unshift(adjacent); - } - } - } - - return graph; -} - -function link(from, to) { - return function (args) { - return to(from(args)); - }; -} - -function wrapConversion(toModel, graph) { - var path$$1 = [graph[toModel].parent, toModel]; - var fn = conversions[graph[toModel].parent][toModel]; - - var cur = graph[toModel].parent; - while (graph[cur].parent) { - path$$1.unshift(graph[cur].parent); - fn = link(conversions[graph[cur].parent][cur], fn); - cur = graph[cur].parent; - } - - fn.conversion = path$$1; - return fn; -} - -var route = function (fromModel) { - var graph = deriveBFS(fromModel); - var conversion = {}; - - var models = Object.keys(graph); - for (var len = models.length, i = 0; i < len; i++) { - var toModel = models[i]; - var node = graph[toModel]; - - if (node.parent === null) { - // no possible conversion, or this node is the source model. - continue; - } - - conversion[toModel] = wrapConversion(toModel, graph); - } - - return conversion; -}; - -var convert = {}; - -var models = Object.keys(conversions); - -function wrapRaw(fn) { - var wrappedFn = function (args) { - if (args === undefined || args === null) { - return args; - } - - if (arguments.length > 1) { - args = Array.prototype.slice.call(arguments); - } - - return fn(args); - }; - - // preserve .conversion property if there is one - if ('conversion' in fn) { - wrappedFn.conversion = fn.conversion; - } - - return wrappedFn; -} - -function wrapRounded(fn) { - var wrappedFn = function (args) { - if (args === undefined || args === null) { - return args; - } - - if (arguments.length > 1) { - args = Array.prototype.slice.call(arguments); - } - - var result = fn(args); - - // we're assuming the result is an array here. - // see notice in conversions.js; don't use box types - // in conversion functions. - if (typeof result === 'object') { - for (var len = result.length, i = 0; i < len; i++) { - result[i] = Math.round(result[i]); - } - } - - return result; - }; - - // preserve .conversion property if there is one - if ('conversion' in fn) { - wrappedFn.conversion = fn.conversion; - } - - return wrappedFn; -} - -models.forEach(function (fromModel) { - convert[fromModel] = {}; - - Object.defineProperty(convert[fromModel], 'channels', {value: conversions[fromModel].channels}); - Object.defineProperty(convert[fromModel], 'labels', {value: conversions[fromModel].labels}); - - var routes = route(fromModel); - var routeModels = Object.keys(routes); - - routeModels.forEach(function (toModel) { - var fn = routes[toModel]; - - convert[fromModel][toModel] = wrapRounded(fn); - convert[fromModel][toModel].raw = wrapRaw(fn); - }); -}); - -var colorConvert = convert; - -var ansiStyles = createCommonjsModule(function (module) { - - -const wrapAnsi16 = (fn, offset) => function () { - const code = fn.apply(colorConvert, arguments); - return `\u001B[${code + offset}m`; -}; - -const wrapAnsi256 = (fn, offset) => function () { - const code = fn.apply(colorConvert, arguments); - return `\u001B[${38 + offset};5;${code}m`; -}; - -const wrapAnsi16m = (fn, offset) => function () { - const rgb = fn.apply(colorConvert, arguments); - return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`; -}; - -function assembleStyles() { - const codes = new Map(); - const styles = { - modifier: { - reset: [0, 0], - // 21 isn't widely supported and 22 does the same thing - bold: [1, 22], - dim: [2, 22], - italic: [3, 23], - underline: [4, 24], - inverse: [7, 27], - hidden: [8, 28], - strikethrough: [9, 29] - }, - color: { - black: [30, 39], - red: [31, 39], - green: [32, 39], - yellow: [33, 39], - blue: [34, 39], - magenta: [35, 39], - cyan: [36, 39], - white: [37, 39], - gray: [90, 39], - - // Bright color - redBright: [91, 39], - greenBright: [92, 39], - yellowBright: [93, 39], - blueBright: [94, 39], - magentaBright: [95, 39], - cyanBright: [96, 39], - whiteBright: [97, 39] - }, - bgColor: { - bgBlack: [40, 49], - bgRed: [41, 49], - bgGreen: [42, 49], - bgYellow: [43, 49], - bgBlue: [44, 49], - bgMagenta: [45, 49], - bgCyan: [46, 49], - bgWhite: [47, 49], - - // Bright color - bgBlackBright: [100, 49], - bgRedBright: [101, 49], - bgGreenBright: [102, 49], - bgYellowBright: [103, 49], - bgBlueBright: [104, 49], - bgMagentaBright: [105, 49], - bgCyanBright: [106, 49], - bgWhiteBright: [107, 49] - } - }; - - // Fix humans - styles.color.grey = styles.color.gray; - - for (const groupName of Object.keys(styles)) { - const group = styles[groupName]; - - for (const styleName of Object.keys(group)) { - const style = group[styleName]; - - styles[styleName] = { - open: `\u001B[${style[0]}m`, - close: `\u001B[${style[1]}m` - }; - - group[styleName] = styles[styleName]; - - codes.set(style[0], style[1]); - } - - Object.defineProperty(styles, groupName, { - value: group, - enumerable: false - }); - - Object.defineProperty(styles, 'codes', { - value: codes, - enumerable: false - }); - } - - const ansi2ansi = n => n; - const rgb2rgb = (r, g, b) => [r, g, b]; - - styles.color.close = '\u001B[39m'; - styles.bgColor.close = '\u001B[49m'; - - styles.color.ansi = { - ansi: wrapAnsi16(ansi2ansi, 0) - }; - styles.color.ansi256 = { - ansi256: wrapAnsi256(ansi2ansi, 0) - }; - styles.color.ansi16m = { - rgb: wrapAnsi16m(rgb2rgb, 0) - }; - - styles.bgColor.ansi = { - ansi: wrapAnsi16(ansi2ansi, 10) - }; - styles.bgColor.ansi256 = { - ansi256: wrapAnsi256(ansi2ansi, 10) - }; - styles.bgColor.ansi16m = { - rgb: wrapAnsi16m(rgb2rgb, 10) - }; - - for (let key of Object.keys(colorConvert)) { - if (typeof colorConvert[key] !== 'object') { - continue; - } - - const suite = colorConvert[key]; - - if (key === 'ansi16') { - key = 'ansi'; - } - - if ('ansi16' in suite) { - styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0); - styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10); - } - - if ('ansi256' in suite) { - styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0); - styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10); - } - - if ('rgb' in suite) { - styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0); - styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10); - } - } - - return styles; -} - -// Make the export immutable -Object.defineProperty(module, 'exports', { - enumerable: true, - get: assembleStyles -}); -}); - -var hasFlag = (flag, argv) => { - argv = argv || process.argv; - const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--'); - const pos = argv.indexOf(prefix + flag); - const terminatorPos = argv.indexOf('--'); - return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos); -}; - -const env = process.env; - -let forceColor; -if (hasFlag('no-color') || - hasFlag('no-colors') || - hasFlag('color=false')) { - forceColor = false; -} else if (hasFlag('color') || - hasFlag('colors') || - hasFlag('color=true') || - hasFlag('color=always')) { - forceColor = true; -} -if ('FORCE_COLOR' in env) { - forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0; -} - -function translateLevel(level) { - if (level === 0) { - return false; - } - - return { - level, - hasBasic: true, - has256: level >= 2, - has16m: level >= 3 - }; -} - -function supportsColor(stream) { - if (forceColor === false) { - return 0; - } - - if (hasFlag('color=16m') || - hasFlag('color=full') || - hasFlag('color=truecolor')) { - return 3; - } - - if (hasFlag('color=256')) { - return 2; - } - - if (stream && !stream.isTTY && forceColor !== true) { - return 0; - } - - const min = forceColor ? 1 : 0; - - if (process.platform === 'win32') { - // Node.js 7.5.0 is the first version of Node.js to include a patch to - // libuv that enables 256 color output on Windows. Anything earlier and it - // won't work. However, here we target Node.js 8 at minimum as it is an LTS - // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows - // release that supports 256 colors. Windows 10 build 14931 is the first release - // that supports 16m/TrueColor. - const osRelease = os.release().split('.'); - if ( - Number(process.versions.node.split('.')[0]) >= 8 && - Number(osRelease[0]) >= 10 && - Number(osRelease[2]) >= 10586 - ) { - return Number(osRelease[2]) >= 14931 ? 3 : 2; - } - - return 1; - } - - if ('CI' in env) { - if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') { - return 1; - } - - return min; - } - - if ('TEAMCITY_VERSION' in env) { - return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0; - } - - if (env.COLORTERM === 'truecolor') { - return 3; - } - - if ('TERM_PROGRAM' in env) { - const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10); - - switch (env.TERM_PROGRAM) { - case 'iTerm.app': - return version >= 3 ? 3 : 2; - case 'Apple_Terminal': - return 2; - // No default - } - } - - if (/-256(color)?$/i.test(env.TERM)) { - return 2; - } - - if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) { - return 1; - } - - if ('COLORTERM' in env) { - return 1; - } - - if (env.TERM === 'dumb') { - return min; - } - - return min; -} - -function getSupportLevel(stream) { - const level = supportsColor(stream); - return translateLevel(level); -} - -var supportsColor_1 = { - supportsColor: getSupportLevel, - stdout: getSupportLevel(process.stdout), - stderr: getSupportLevel(process.stderr) -}; - -const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi; -const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g; -const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/; -const ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi; - -const ESCAPES = new Map([ - ['n', '\n'], - ['r', '\r'], - ['t', '\t'], - ['b', '\b'], - ['f', '\f'], - ['v', '\v'], - ['0', '\0'], - ['\\', '\\'], - ['e', '\u001B'], - ['a', '\u0007'] -]); - -function unescape(c) { - if ((c[0] === 'u' && c.length === 5) || (c[0] === 'x' && c.length === 3)) { - return String.fromCharCode(parseInt(c.slice(1), 16)); - } - - return ESCAPES.get(c) || c; -} - -function parseArguments(name, args) { - const results = []; - const chunks = args.trim().split(/\s*,\s*/g); - let matches; - - for (const chunk of chunks) { - if (!isNaN(chunk)) { - results.push(Number(chunk)); - } else if ((matches = chunk.match(STRING_REGEX))) { - results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, chr) => escape ? unescape(escape) : chr)); - } else { - throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`); - } - } - - return results; + return inputOptions; } - -function parseStyle(style) { - STYLE_REGEX.lastIndex = 0; - - const results = []; - let matches; - - while ((matches = STYLE_REGEX.exec(style)) !== null) { - const name = matches[1]; - - if (matches[2]) { - const args = parseArguments(name, matches[2]); - results.push([name].concat(args)); - } else { - results.push([name]); - } - } - - return results; +function getOutputOptions(config, command) { + if (command === void 0) { command = {}; } + var getOption = createGetOption(config, command); + var format = getOption('format'); + return { + amd: __assign({}, config.amd, command.amd), + assetFileNames: getOption('assetFileNames'), + banner: getOption('banner'), + dir: getOption('dir'), + chunkFileNames: getOption('chunkFileNames'), + compact: getOption('compact', false), + entryFileNames: getOption('entryFileNames'), + esModule: getOption('esModule', true), + exports: getOption('exports'), + extend: getOption('extend'), + file: getOption('file'), + footer: getOption('footer'), + format: format === 'esm' ? 'es' : format, + freeze: getOption('freeze', true), + globals: getOption('globals'), + indent: getOption('indent', true), + interop: getOption('interop', true), + intro: getOption('intro'), + name: getOption('name'), + namespaceToStringTag: getOption('namespaceToStringTag', false), + noConflict: getOption('noConflict'), + outro: getOption('outro'), + paths: getOption('paths'), + sourcemap: getOption('sourcemap'), + sourcemapExcludeSources: getOption('sourcemapExcludeSources'), + sourcemapFile: getOption('sourcemapFile'), + sourcemapPathTransform: getOption('sourcemapPathTransform'), + strict: getOption('strict', true) + }; } - -function buildStyle(chalk, styles) { - const enabled = {}; - - for (const layer of styles) { - for (const style of layer.styles) { - enabled[style[0]] = layer.inverse ? null : style.slice(1); - } - } - - let current = chalk; - for (const styleName of Object.keys(enabled)) { - if (Array.isArray(enabled[styleName])) { - if (!(styleName in current)) { - throw new Error(`Unknown Chalk style: ${styleName}`); - } - - if (enabled[styleName].length > 0) { - current = current[styleName].apply(current, enabled[styleName]); - } else { - current = current[styleName]; - } - } - } - - return current; +function deprecate(config, command, deprecateConfig) { + if (command === void 0) { command = {}; } + if (deprecateConfig === void 0) { deprecateConfig = { input: true, output: true }; } + var deprecations = []; + // CLI + if (command.id) { + deprecations.push({ + old: '-u/--id', + new: '--amd.id' + }); + (command.amd || (command.amd = {})).id = command.id; + } + if (typeof command.output === 'string') { + deprecations.push({ + old: '--output', + new: '--file' + }); + command.output = { file: command.output }; + } + if (command.d) { + deprecations.push({ + old: '-d', + new: '--indent' + }); + command.indent = command.d; + } + // config file + deprecations.push.apply(deprecations, deprecateOptions(config, deprecateConfig)); + return deprecations; } -var templates = (chalk, tmp) => { - const styles = []; - const chunks = []; - let chunk = []; - - // eslint-disable-next-line max-params - tmp.replace(TEMPLATE_REGEX, (m, escapeChar, inverse, style, close, chr) => { - if (escapeChar) { - chunk.push(unescape(escapeChar)); - } else if (style) { - const str = chunk.join(''); - chunk = []; - chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str)); - styles.push({inverse, styles: parseStyle(style)}); - } else if (close) { - if (styles.length === 0) { - throw new Error('Found extraneous } in Chalk template literal'); - } - - chunks.push(buildStyle(chalk, styles)(chunk.join(''))); - chunk = []; - styles.pop(); - } else { - chunk.push(chr); - } - }); - - chunks.push(chunk.join('')); - - if (styles.length > 0) { - const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`; - throw new Error(errMsg); - } +var modules = {}; - return chunks.join(''); +var getModule = function(dir) { + var rootPath = dir ? path__default.resolve(dir) : process.cwd(); + var rootName = path__default.join(rootPath, '@root'); + var root = modules[rootName]; + if (!root) { + root = new module$1(rootName); + root.filename = rootName; + root.paths = module$1._nodeModulePaths(rootPath); + modules[rootName] = root; + } + return root; }; -var chalk = createCommonjsModule(function (module) { - - -const stdoutColor = supportsColor_1.stdout; - - - -const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); - -// `supportsColor.level` → `ansiStyles.color[name]` mapping -const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; - -// `color-convert` models to exclude from the Chalk API due to conflicts and such -const skipModels = new Set(['gray']); - -const styles = Object.create(null); - -function applyOptions(obj, options) { - options = options || {}; - - // Detect level if not set manually - const scLevel = stdoutColor ? stdoutColor.level : 0; - obj.level = options.level === undefined ? scLevel : options.level; - obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0; -} - -function Chalk(options) { - // We check for this.template here since calling `chalk.constructor()` - // by itself will have a `this` of a previously constructed chalk object - if (!this || !(this instanceof Chalk) || this.template) { - const chalk = {}; - applyOptions(chalk, options); - - chalk.template = function () { - const args = [].slice.call(arguments); - return chalkTag.apply(null, [chalk.template].concat(args)); - }; - - Object.setPrototypeOf(chalk, Chalk.prototype); - Object.setPrototypeOf(chalk.template, chalk); - - chalk.template.constructor = Chalk; - - return chalk.template; - } - - applyOptions(this, options); -} - -// Use bright blue on Windows as the normal blue color is illegible -if (isSimpleWindowsTerm) { - ansiStyles.blue.open = '\u001B[94m'; -} - -for (const key of Object.keys(ansiStyles)) { - ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g'); - - styles[key] = { - get() { - const codes = ansiStyles[key]; - return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key); - } - }; -} - -styles.visible = { - get() { - return build.call(this, this._styles || [], true, 'visible'); - } +var requireRelative = function(requested, relativeTo) { + var root = getModule(relativeTo); + return root.require(requested); }; -ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g'); -for (const model of Object.keys(ansiStyles.color.ansi)) { - if (skipModels.has(model)) { - continue; - } - - styles[model] = { - get() { - const level = this.level; - return function () { - const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments); - const codes = { - open, - close: ansiStyles.color.close, - closeRe: ansiStyles.color.closeRe - }; - return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model); - }; - } - }; -} +requireRelative.resolve = function(requested, relativeTo) { + var root = getModule(relativeTo); + return module$1._resolveFilename(requested, root); +}; -ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g'); -for (const model of Object.keys(ansiStyles.bgColor.ansi)) { - if (skipModels.has(model)) { - continue; - } +var requireRelative_1 = requireRelative; - const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1); - styles[bgModel] = { - get() { - const level = this.level; - return function () { - const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments); - const codes = { - open, - close: ansiStyles.bgColor.close, - closeRe: ansiStyles.bgColor.closeRe - }; - return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model); - }; - } - }; +var absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/; +function isAbsolute(path$$1) { + return absolutePath.test(path$$1); } -const proto = Object.defineProperties(() => {}, styles); - -function build(_styles, _empty, key) { - const builder = function () { - return applyStyle.apply(builder, arguments); - }; - - builder._styles = _styles; - builder._empty = _empty; - - const self = this; - - Object.defineProperty(builder, 'level', { - enumerable: true, - get() { - return self.level; - }, - set(level) { - self.level = level; - } - }); - - Object.defineProperty(builder, 'enabled', { - enumerable: true, - get() { - return self.enabled; - }, - set(enabled) { - self.enabled = enabled; - } - }); - - // See below for fix regarding invisible grey/dim combination on Windows - builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; - - // `__proto__` is used because we must return a function, but there is - // no way to create a function with a different prototype - builder.__proto__ = proto; // eslint-disable-line no-proto - - return builder; +function getAliasName(resolved, unresolved) { + var alias = path.basename(unresolved || resolved); + var ext = path.extname(resolved); + if (alias.endsWith(ext)) + alias = alias.substr(0, alias.length - ext.length); + return alias; } - -function applyStyle() { - // Support varags, but simply cast to string in case there's only one arg - const args = arguments; - const argsLen = args.length; - let str = String(arguments[0]); - - if (argsLen === 0) { - return ''; - } - - if (argsLen > 1) { - // Don't slice `arguments`, it prevents V8 optimizations - for (let a = 1; a < argsLen; a++) { - str += ' ' + args[a]; - } - } - - if (!this.enabled || this.level <= 0 || !str) { - return this._empty ? '' : str; - } - - // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe, - // see https://github.com/chalk/chalk/issues/58 - // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop. - const originalDim = ansiStyles.dim.open; - if (isSimpleWindowsTerm && this.hasGrey) { - ansiStyles.dim.open = ''; - } - - for (const code of this._styles.slice().reverse()) { - // Replace any instances already present with a re-opening code - // otherwise only the part of the string until said closing code - // will be colored, and the rest will simply be 'plain'. - str = code.open + str.replace(code.closeRe, code.open) + code.close; - - // Close the styling before a linebreak and reopen - // after next line to fix a bleed issue on macOS - // https://github.com/chalk/chalk/pull/92 - str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`); - } - - // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue - ansiStyles.dim.open = originalDim; - - return str; +function relativeId(id) { + if (typeof process === 'undefined' || !isAbsolute(id)) + return id; + return path.relative(process.cwd(), id); } -function chalkTag(chalk, strings) { - if (!Array.isArray(strings)) { - // If chalk() was called by itself or with a string, - // return the string itself as a string. - return [].slice.call(arguments, 1).join(' '); - } - - const args = [].slice.call(arguments, 2); - const parts = [strings.raw[0]]; - - for (let i = 1; i < strings.length; i++) { - parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&')); - parts.push(String(strings.raw[i])); - } - - return templates(chalk, parts.join('')); -} +const tc = { + enabled: + process.env.FORCE_COLOR || + process.platform === "win32" || + (process.stdout.isTTY && process.env.TERM && process.env.TERM !== "dumb") +}; +const Styles = (tc.Styles = {}); +const defineProp = Object.defineProperty; + +const init = (style, open, close, re) => { + let i, + len = 1, + seq = [(Styles[style] = { open, close, re })]; + + const fn = s => { + if (tc.enabled) { + for (i = 0, s += ""; i < len; i++) { + style = seq[i]; + s = + (open = style.open) + + (~s.indexOf((close = style.close), 4) // skip first \x1b[ + ? s.replace(style.re, open) + : s) + + close; + } + len = 1; + } + return s + }; -Object.defineProperties(Chalk.prototype, styles); + defineProp(tc, style, { + get: () => { + for (let k in Styles) + defineProp(fn, k, { + get: () => ((seq[len++] = Styles[k]), fn) + }); + delete tc[style]; + return (tc[style] = fn) + }, + configurable: true + }); +}; -module.exports = Chalk(); // eslint-disable-line new-cap -module.exports.supportsColor = stdoutColor; -module.exports.default = module.exports; // For TypeScript -}); -var chalk_1 = chalk.supportsColor; +init("reset", "\x1b[0m", "\x1b[0m", /\x1b\[0m/g); +init("bold", "\x1b[1m", "\x1b[22m", /\x1b\[22m/g); +init("dim", "\x1b[2m", "\x1b[22m", /\x1b\[22m/g); +init("italic", "\x1b[3m", "\x1b[23m", /\x1b\[23m/g); +init("underline", "\x1b[4m", "\x1b[24m", /\x1b\[24m/g); +init("inverse", "\x1b[7m", "\x1b[27m", /\x1b\[27m/g); +init("hidden", "\x1b[8m", "\x1b[28m", /\x1b\[28m/g); +init("strikethrough", "\x1b[9m", "\x1b[29m", /\x1b\[29m/g); +init("black", "\x1b[30m", "\x1b[39m", /\x1b\[39m/g); +init("red", "\x1b[31m", "\x1b[39m", /\x1b\[39m/g); +init("green", "\x1b[32m", "\x1b[39m", /\x1b\[39m/g); +init("yellow", "\x1b[33m", "\x1b[39m", /\x1b\[39m/g); +init("blue", "\x1b[34m", "\x1b[39m", /\x1b\[39m/g); +init("magenta", "\x1b[35m", "\x1b[39m", /\x1b\[39m/g); +init("cyan", "\x1b[36m", "\x1b[39m", /\x1b\[39m/g); +init("white", "\x1b[37m", "\x1b[39m", /\x1b\[39m/g); +init("gray", "\x1b[90m", "\x1b[39m", /\x1b\[39m/g); +init("bgBlack", "\x1b[40m", "\x1b[49m", /\x1b\[49m/g); +init("bgRed", "\x1b[41m", "\x1b[49m", /\x1b\[49m/g); +init("bgGreen", "\x1b[42m", "\x1b[49m", /\x1b\[49m/g); +init("bgYellow", "\x1b[43m", "\x1b[49m", /\x1b\[49m/g); +init("bgBlue", "\x1b[44m", "\x1b[49m", /\x1b\[49m/g); +init("bgMagenta", "\x1b[45m", "\x1b[49m", /\x1b\[49m/g); +init("bgCyan", "\x1b[46m", "\x1b[49m", /\x1b\[49m/g); +init("bgWhite", "\x1b[47m", "\x1b[49m", /\x1b\[49m/g); + +var turbocolor = tc; -if (!chalk.supportsColor) - chalk.enabled = false; // log to stderr to keep `rollup main.js > bundle.js` from breaking var stderr = console.error.bind(console); // eslint-disable-line no-console function handleError(err, recover) { @@ -2543,10 +738,9 @@ function handleError(err, recover) { var message = (err.plugin ? "(" + err.plugin + " plugin) " + description : description) || err; - stderr(chalk.bold.red("[!] " + chalk.bold(message.toString()))); - // TODO should this be "err.url || (err.file && err.loc.file) || err.id"? + stderr(turbocolor.bold.red("[!] " + turbocolor.bold(message.toString()))); if (err.url) { - stderr(chalk.cyan(err.url)); + stderr(turbocolor.cyan(err.url)); } if (err.loc) { stderr(relativeId(err.loc.file || err.id) + " (" + err.loc.line + ":" + err.loc.column + ")"); @@ -2555,31 +749,16 @@ function handleError(err, recover) { stderr(relativeId(err.id)); } if (err.frame) { - stderr(chalk.dim(err.frame)); + stderr(turbocolor.dim(err.frame)); } - else if (err.stack) { - stderr(chalk.dim(err.stack)); + if (err.stack) { + stderr(turbocolor.dim(err.stack)); } stderr(''); if (!recover) process.exit(1); } -function sequence(array, fn) { - var results = []; - var promise = Promise.resolve(); - function next(member, i) { - return fn(member).then(function (value) { return (results[i] = value); }); - } - var _loop_1 = function (i) { - promise = promise.then(function () { return next(array[i], i); }); - }; - for (var i = 0; i < array.length; i += 1) { - _loop_1(i); - } - return promise.then(function () { return results; }); -} - function batchWarnings() { var allWarnings = new Map(); var count = 0; @@ -2621,7 +800,7 @@ function batchWarnings() { } else { warnings.forEach(function (warning) { - stderr(chalk.bold.yellow('(!)') + " " + chalk.bold.yellow(warning.message)); + stderr(turbocolor.bold.yellow('(!)') + " " + turbocolor.bold.yellow(warning.message)); if (warning.url) info(warning.url); var id = (warning.loc && warning.loc.file) || warning.id; @@ -2629,7 +808,7 @@ function batchWarnings() { var loc = warning.loc ? relativeId(id) + ": (" + warning.loc.line + ":" + warning.loc.column + ")" : relativeId(id); - stderr(chalk.bold(relativeId(loc))); + stderr(turbocolor.bold(relativeId(loc))); } if (warning.frame) info(warning.frame); @@ -2650,7 +829,7 @@ var immediateHandlers = { title("Some options have been renamed"); info("https://gist.github.com/Rich-Harris/d472c50732dab03efeb37472b08a3f32"); warning.deprecations.forEach(function (option) { - stderr(chalk.bold(option.old) + " is now " + option.new); + stderr(turbocolor.bold(option.old) + " is now " + option.new); }); }, MISSING_NODE_BUILTINS: function (warning) { @@ -2686,7 +865,7 @@ var deferredHandlers = { priority: 1, fn: function (warnings) { title('Unresolved dependencies'); - info('https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency'); + info('https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency'); var dependencies = new Map(); warnings.forEach(function (warning) { if (!dependencies.has(warning.source)) @@ -2695,7 +874,7 @@ var deferredHandlers = { }); Array.from(dependencies.keys()).forEach(function (dependency) { var importers = dependencies.get(dependency); - stderr(chalk.bold(dependency) + " (imported by " + importers.join(', ') + ")"); + stderr(turbocolor.bold(dependency) + " (imported by " + importers.join(', ') + ")"); }); } }, @@ -2703,11 +882,11 @@ var deferredHandlers = { priority: 1, fn: function (warnings) { title('Missing exports'); - info('https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module'); + info('https://rollupjs.org/guide/en#error-name-is-not-exported-by-module-'); warnings.forEach(function (warning) { - stderr(chalk.bold(warning.importer)); + stderr(turbocolor.bold(warning.importer)); stderr(warning.missing + " is not exported by " + warning.exporter); - stderr(chalk.grey(warning.frame)); + stderr(turbocolor.gray(warning.frame)); }); } }, @@ -2715,7 +894,7 @@ var deferredHandlers = { priority: 1, fn: function (warnings) { title('`this` has been rewritten to `undefined`'); - info('https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined'); + info('https://rollupjs.org/guide/en#error-this-is-undefined'); showTruncatedWarnings(warnings); } }, @@ -2723,7 +902,7 @@ var deferredHandlers = { priority: 1, fn: function (warnings) { title('Use of eval is strongly discouraged'); - info('https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval'); + info('https://rollupjs.org/guide/en#avoiding-eval'); showTruncatedWarnings(warnings); } }, @@ -2739,7 +918,7 @@ var deferredHandlers = { fn: function (warnings) { title("Conflicting re-exports"); warnings.forEach(function (warning) { - stderr(chalk.bold(relativeId(warning.reexporter)) + " re-exports '" + warning.name + "' from both " + relativeId(warning.sources[0]) + " and " + relativeId(warning.sources[1]) + " (will be ignored)"); + stderr(turbocolor.bold(relativeId(warning.reexporter)) + " re-exports '" + warning.name + "' from both " + relativeId(warning.sources[0]) + " and " + relativeId(warning.sources[1]) + " (will be ignored)"); }); } }, @@ -2749,7 +928,7 @@ var deferredHandlers = { title("Missing global variable " + (warnings.length > 1 ? 'names' : 'name')); stderr("Use output.globals to specify browser global variable names corresponding to external modules"); warnings.forEach(function (warning) { - stderr(chalk.bold(warning.source) + " (guessing '" + warning.guess + "')"); + stderr(turbocolor.bold(warning.source) + " (guessing '" + warning.guess + "')"); }); } }, @@ -2757,7 +936,7 @@ var deferredHandlers = { priority: 1, fn: function (warnings) { title("Broken sourcemap"); - info('https://github.com/rollup/rollup/wiki/Troubleshooting#sourcemap-is-likely-to-be-incorrect'); + info('https://rollupjs.org/guide/en#warning-sourcemap-is-likely-to-be-incorrect'); var plugins = Array.from(new Set(warnings.map(function (w) { return w.plugin; }).filter(Boolean))); var detail = plugins.length === 0 ? '' @@ -2787,7 +966,7 @@ var deferredHandlers = { var loc = warning.loc ? relativeId(warning.id) + ": (" + warning.loc.line + ":" + warning.loc.column + ")" : relativeId(warning.id); - stderr(chalk.bold(relativeId(loc))); + stderr(turbocolor.bold(relativeId(loc))); if (warning.frame) info(warning.frame); }); @@ -2797,10 +976,10 @@ var deferredHandlers = { } }; function title(str) { - stderr(chalk.bold.yellow('(!)') + " " + chalk.bold.yellow(str)); + stderr(turbocolor.bold.yellow('(!)') + " " + turbocolor.bold.yellow(str)); } function info(url) { - stderr(chalk.grey(url)); + stderr(turbocolor.gray(url)); } function nest(array, prop) { var nested = []; @@ -2823,8 +1002,8 @@ function showTruncatedWarnings(warnings) { var sliced = nestedByModule.length > 5 ? nestedByModule.slice(0, 3) : nestedByModule; sliced.forEach(function (_a) { var id = _a.key, items = _a.items; - stderr(chalk.bold(relativeId(id))); - stderr(chalk.grey(items[0].frame)); + stderr(turbocolor.bold(relativeId(id))); + stderr(turbocolor.gray(items[0].frame)); if (items.length > 1) { stderr("...and " + (items.length - 1) + " other " + (items.length > 2 ? 'occurrences' : 'occurrence')); } @@ -2834,48 +1013,57 @@ function showTruncatedWarnings(warnings) { } } -var parseMs = function (ms) { +var parseMs = ms => { if (typeof ms !== 'number') { throw new TypeError('Expected a number'); } - var roundTowardZero = ms > 0 ? Math.floor : Math.ceil; + const roundTowardsZero = ms > 0 ? Math.floor : Math.ceil; return { - days: roundTowardZero(ms / 86400000), - hours: roundTowardZero(ms / 3600000) % 24, - minutes: roundTowardZero(ms / 60000) % 60, - seconds: roundTowardZero(ms / 1000) % 60, - milliseconds: roundTowardZero(ms) % 1000 + days: roundTowardsZero(ms / 86400000), + hours: roundTowardsZero(ms / 3600000) % 24, + minutes: roundTowardsZero(ms / 60000) % 60, + seconds: roundTowardsZero(ms / 1000) % 60, + milliseconds: roundTowardsZero(ms) % 1000, + microseconds: roundTowardsZero(ms * 1000) % 1000, + nanoseconds: roundTowardsZero(ms * 1e6) % 1000 }; }; -const plur = (word, count) => count === 1 ? word : word + 's'; +const pluralize = (word, count) => count === 1 ? word : word + 's'; -var prettyMs = (ms, opts) => { +var prettyMs = (ms, options = {}) => { if (!Number.isFinite(ms)) { throw new TypeError('Expected a finite number'); } - opts = opts || {}; - - if (ms < 1000) { - const msDecimalDigits = typeof opts.msDecimalDigits === 'number' ? opts.msDecimalDigits : 0; - return (msDecimalDigits ? ms.toFixed(msDecimalDigits) : Math.ceil(ms)) + (opts.verbose ? ' ' + plur('millisecond', Math.ceil(ms)) : 'ms'); + if (options.compact) { + options.secDecimalDigits = 0; + options.msDecimalDigits = 0; } const ret = []; - const add = (val, long, short, valStr) => { - if (val === 0) { + const add = (value, long, short, valueString) => { + if (value === 0) { return; } - const postfix = opts.verbose ? ' ' + plur(long, val) : short; + const postfix = options.verbose ? ' ' + pluralize(long, value) : short; - ret.push((valStr || val) + postfix); + ret.push((valueString || value) + postfix); }; + const secDecimalDigits = typeof options.secDecimalDigits === 'number' ? options.secDecimalDigits : 1; + + if (secDecimalDigits < 1) { + const diff = 1000 - (ms % 1000); + if (diff < 500) { + ms += diff; + } + } + const parsed = parseMs(ms); add(Math.trunc(parsed.days / 365), 'year', 'y'); @@ -2883,49 +1071,112 @@ var prettyMs = (ms, opts) => { add(parsed.hours, 'hour', 'h'); add(parsed.minutes, 'minute', 'm'); - if (opts.compact) { + if (options.separateMs || options.formatSubMs || ms < 1000) { add(parsed.seconds, 'second', 's'); + if (options.formatSubMs) { + add(parsed.milliseconds, 'millisecond', 'ms'); + add(parsed.microseconds, 'microsecond', 'µs'); + add(parsed.nanoseconds, 'nanosecond', 'ns'); + } else { + const msAndBelow = parsed.milliseconds + (parsed.microseconds / 1000) + (parsed.nanoseconds / 1e6); + const msDecimalDigits = typeof options.msDecimalDigits === 'number' ? options.msDecimalDigits : 0; + const msStr = msDecimalDigits ? msAndBelow.toFixed(msDecimalDigits) : Math.ceil(msAndBelow); + add(parseFloat(msStr, 10), 'millisecond', 'ms', msStr); + } + } else { + const sec = ms / 1000 % 60; + const secDecimalDigits = typeof options.secDecimalDigits === 'number' ? options.secDecimalDigits : 1; + const secFixed = sec.toFixed(secDecimalDigits); + const secStr = options.keepDecimalsOnWholeSeconds ? secFixed : secFixed.replace(/\.0+$/, ''); + add(parseFloat(secStr, 10), 'second', 's', secStr); + } + + if (ret.length === 0) { + return '0' + (options.verbose ? ' milliseconds' : 'ms'); + } + + if (options.compact) { return '~' + ret[0]; } - const sec = ms / 1000 % 60; - const secDecimalDigits = typeof opts.secDecimalDigits === 'number' ? opts.secDecimalDigits : 1; - const secFixed = sec.toFixed(secDecimalDigits); - const secStr = opts.keepDecimalsOnWholeSeconds ? secFixed : secFixed.replace(/\.0+$/, ''); - add(sec, 'second', 's', secStr); + if (typeof options.unitCount === 'number') { + return '~' + ret.slice(0, Math.max(options.unitCount, 1)).join(' '); + } return ret.join(' '); }; -function mapSequence(array, fn) { - var results = []; - var promise = Promise.resolve(); - function next(member, i) { - return Promise.resolve(fn(member)).then(function (value) { return (results[i] = value); }); - } - var _loop_1 = function (i) { - promise = promise.then(function () { return next(array[i], i); }); - }; - for (var i = 0; i < array.length; i += 1) { - _loop_1(i); - } - return promise.then(function () { return results; }); -} - var SOURCEMAPPING_URL = 'sourceMa'; SOURCEMAPPING_URL += 'ppingURL'; var SOURCEMAPPING_URL$1 = SOURCEMAPPING_URL; +const UNITS = [ + 'B', + 'kB', + 'MB', + 'GB', + 'TB', + 'PB', + 'EB', + 'ZB', + 'YB' +]; + +/* +Formats the given number using `Number#toLocaleString`. +- If locale is a string, the value is expected to be a locale-key (for example: `de`). +- If locale is true, the system default locale is used for translation. +- If no value for locale is specified, the number is returned unmodified. +*/ +const toLocaleString = (number, locale) => { + let result = number; + if (typeof locale === 'string') { + result = number.toLocaleString(locale); + } else if (locale === true) { + result = number.toLocaleString(); + } + + return result; +}; + +var prettyBytes = (number, options) => { + if (!Number.isFinite(number)) { + throw new TypeError(`Expected a finite number, got ${typeof number}: ${number}`); + } + + options = Object.assign({}, options); + + if (options.signed && number === 0) { + return ' 0 B'; + } + + const isNegative = number < 0; + const prefix = isNegative ? '-' : (options.signed ? '+' : ''); + + if (isNegative) { + number = -number; + } + + if (number < 1) { + const numberString = toLocaleString(number, options.locale); + return prefix + numberString + ' B'; + } + + const exponent = Math.min(Math.floor(Math.log10(number) / 3), UNITS.length - 1); + number = Number((number / Math.pow(1000, exponent)).toPrecision(3)); + const numberString = toLocaleString(number, options.locale); + + const unit = UNITS[exponent]; + + return prefix + numberString + ' ' + unit; +}; + function printTimings(timings) { Object.keys(timings).forEach(function (label) { - var color = chalk; - if (label[0] === '#') { - color = color.bold; - if (label[1] !== '#') { - color = color.underline; - } - } - console.info(color(label + ": " + timings[label].toFixed(0) + "ms")); + var color = label[0] === '#' ? (label[1] !== '#' ? turbocolor.underline : turbocolor.bold) : function (text) { return text; }; + var _a = timings[label], time = _a[0], memory = _a[1], total = _a[2]; + var row = label + ": " + time.toFixed(0) + "ms, " + prettyBytes(memory) + " / " + prettyBytes(total); + console.info(color(row)); }); } @@ -2951,7 +1202,7 @@ function build(inputOptions, outputOptions, warnings, silent) { .map(function (name) { return inputOptions.input[name]; }) .join(', '); } - stderr(chalk.cyan("\n" + chalk.bold(inputFiles) + " \u2192 " + chalk.bold(files.join(', ')) + "...")); + stderr(turbocolor.cyan("\n" + turbocolor.bold(inputFiles) + " \u2192 " + turbocolor.bold(files.join(', ')) + "...")); } return rollup.rollup(inputOptions) .then(function (bundle) { @@ -2973,17 +1224,21 @@ function build(inputOptions, outputOptions, warnings, silent) { process.stdout.write(code); }); } - return mapSequence(outputOptions, function (output) { return bundle.write(output); }).then(function () { return bundle; }); + return Promise.all(outputOptions.map(function (output) { return bundle.write(output); })).then(function () { return bundle; }); }) .then(function (bundle) { warnings.flush(); if (!silent) - stderr(chalk.green("created " + chalk.bold(files.join(', ')) + " in " + chalk.bold(prettyMs(Date.now() - start)))); + stderr(turbocolor.green("created " + turbocolor.bold(files.join(', ')) + " in " + turbocolor.bold(prettyMs(Date.now() - start)))); if (bundle && bundle.getTimings) { printTimings(bundle.getTimings()); } }) - .catch(handleError); + .catch(function (err) { + if (warnings.count > 0) + warnings.flush(); + handleError(err); + }); } function loadConfigFile(configFile, commandOptions) { @@ -3000,7 +1255,7 @@ function loadConfigFile(configFile, commandOptions) { }) .then(function (bundle) { if (!silent && warnings.count > 0) { - stderr(chalk.bold("loaded " + relativeId(configFile) + " with warnings")); + stderr(turbocolor.bold("loaded " + relativeId(configFile) + " with warnings")); warnings.flush(); } return bundle.generate({ @@ -3032,7 +1287,7 @@ function loadConfigFile(configFile, commandOptions) { handleError({ code: 'MISSING_CONFIG', message: 'Config file must export an options object, or an array of options objects', - url: 'https://rollupjs.org/#using-config-files' + url: 'https://rollupjs.org/guide/en#configuration-files' }); } require.extensions['.js'] = defaultLoader; @@ -3082,6 +1337,10 @@ var dateTime = options => { .replace(/\..+/, end); }; +function createCommonjsModule(fn, module) { + return module = { exports: {} }, fn(module, module.exports), module.exports; +} + var signals = createCommonjsModule(function (module) { // This is not the set of all possible signals. // @@ -3511,7 +1770,9 @@ function watch(configFile, configs, command, silent) { handleError(event.error, true); break; case 'START': - screenWriter(chalk.underline("rollup v" + rollup.VERSION)); + if (!silent) { + screenWriter(turbocolor.underline("rollup v" + rollup.VERSION)); + } break; case 'BUNDLE_START': if (!silent) { @@ -3523,13 +1784,13 @@ function watch(configFile, configs, command, silent) { .map(function (key) { return input_1[key]; }) .join(', '); } - stderr(chalk.cyan("bundles " + chalk.bold(input_1) + " \u2192 " + chalk.bold(event.output.map(relativeId).join(', ')) + "...")); + stderr(turbocolor.cyan("bundles " + turbocolor.bold(input_1) + " \u2192 " + turbocolor.bold(event.output.map(relativeId).join(', ')) + "...")); } break; case 'BUNDLE_END': warnings.flush(); if (!silent) - stderr(chalk.green("created " + chalk.bold(event.output.map(relativeId).join(', ')) + " in " + chalk.bold(prettyMs(event.duration)))); + stderr(turbocolor.green("created " + turbocolor.bold(event.output.map(relativeId).join(', ')) + " in " + turbocolor.bold(prettyMs(event.duration)))); if (event.result && event.result.getTimings) { printTimings(event.result.getTimings()); } @@ -3547,7 +1808,6 @@ function watch(configFile, configs, command, silent) { // only listen to stdin if it is a pipe if (!process.stdin.isTTY) { process.stdin.on('end', close); // in case we ever support stdin! - process.stdin.resume(); } function close(err) { removeOnExit(); @@ -3701,26 +1961,34 @@ function execute(configFile, configs, command) { watch(configFile, configs, command, command.silent); } else { - return sequence(configs, function (config) { - var warnings = batchWarnings(); - var _a = mergeOptions({ - config: config, - command: command, - defaultOnWarnHandler: warnings.add - }), inputOptions = _a.inputOptions, outputOptions = _a.outputOptions, deprecations = _a.deprecations, optionError = _a.optionError; - if (deprecations.length) { - inputOptions.onwarn({ - code: 'DEPRECATED_OPTIONS', - message: "The following options have been renamed \u2014 please update your config: " + deprecations - .map(function (option) { return option.old + " -> " + option.new; }) - .join(', '), - deprecations: deprecations - }); - } - if (optionError) - inputOptions.onwarn({ code: 'UNKNOWN_OPTION', message: optionError }); - return build(inputOptions, outputOptions, warnings, command.silent); - }); + var promise = Promise.resolve(); + var _loop_1 = function (config) { + promise = promise.then(function () { + var warnings = batchWarnings(); + var _a = mergeOptions({ + config: config, + command: command, + defaultOnWarnHandler: warnings.add + }), inputOptions = _a.inputOptions, outputOptions = _a.outputOptions, deprecations = _a.deprecations, optionError = _a.optionError; + if (deprecations.length) { + inputOptions.onwarn({ + code: 'DEPRECATED_OPTIONS', + message: "The following options have been renamed \u2014 please update your config: " + deprecations + .map(function (option) { return option.old + " -> " + option.new; }) + .join(', '), + deprecations: deprecations + }); + } + if (optionError) + inputOptions.onwarn({ code: 'UNKNOWN_OPTION', message: optionError }); + return build(inputOptions, outputOptions, warnings, command.silent); + }); + }; + for (var _i = 0, configs_1 = configs; _i < configs_1.length; _i++) { + var config = configs_1[_i]; + _loop_1(config); + } + return promise; } } @@ -3731,7 +1999,7 @@ if (command.help || (process.argv.length <= 2 && process.stdin.isTTY)) { console.log("\n" + help.replace('__VERSION__', version) + "\n"); // eslint-disable-line no-console } else if (command.version) { - console.log("rollup version " + version); // eslint-disable-line no-console + console.log("rollup v" + version); // eslint-disable-line no-console } else { try { diff --git a/node_modules/rollup/dist/rollup.browser.js b/node_modules/rollup/dist/rollup.browser.js index cb05f74bdb..c149a64934 100644 --- a/node_modules/rollup/dist/rollup.browser.js +++ b/node_modules/rollup/dist/rollup.browser.js @@ -1,22402 +1,12 @@ /* - Rollup.js v0.63.2 - Wed, 18 Jul 2018 08:01:51 GMT - commit afddd9fba87f445c1dce29767f19551358c4d91d + @license + Rollup.js v0.66.6 + Fri, 26 Oct 2018 21:41:00 GMT - commit 9c44a12f07664b88f509061e46bf16cd48d3e670 https://github.com/rollup/rollup Released under the MIT License. */ -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : - typeof define === 'function' && define.amd ? define(['exports'], factory) : - (factory((global.rollup = {}))); -}(this, (function (exports) { 'use strict'; - - var minimalisticAssert = assert; - - function assert(val, msg) { - if (!val) - throw new Error(msg || 'Assertion failed'); - } - - assert.equal = function assertEqual(l, r, msg) { - if (l != r) - throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r)); - }; - - var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; - - function unwrapExports (x) { - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; - } - - function createCommonjsModule(fn, module) { - return module = { exports: {} }, fn(module, module.exports), module.exports; - } - - var inherits_browser = createCommonjsModule(function (module) { - if (typeof Object.create === 'function') { - // implementation from standard node.js 'util' module - module.exports = function inherits(ctor, superCtor) { - ctor.super_ = superCtor; - ctor.prototype = Object.create(superCtor.prototype, { - constructor: { - value: ctor, - enumerable: false, - writable: true, - configurable: true - } - }); - }; - } else { - // old school shim for old browsers - module.exports = function inherits(ctor, superCtor) { - ctor.super_ = superCtor; - var TempCtor = function () {}; - TempCtor.prototype = superCtor.prototype; - ctor.prototype = new TempCtor(); - ctor.prototype.constructor = ctor; - }; - } - }); - - var inherits_1 = inherits_browser; - - function toArray(msg, enc) { - if (Array.isArray(msg)) - return msg.slice(); - if (!msg) - return []; - var res = []; - if (typeof msg === 'string') { - if (!enc) { - for (var i = 0; i < msg.length; i++) { - var c = msg.charCodeAt(i); - var hi = c >> 8; - var lo = c & 0xff; - if (hi) - res.push(hi, lo); - else - res.push(lo); - } - } else if (enc === 'hex') { - msg = msg.replace(/[^a-z0-9]+/ig, ''); - if (msg.length % 2 !== 0) - msg = '0' + msg; - for (i = 0; i < msg.length; i += 2) - res.push(parseInt(msg[i] + msg[i + 1], 16)); - } - } else { - for (i = 0; i < msg.length; i++) - res[i] = msg[i] | 0; - } - return res; - } - var toArray_1 = toArray; - - function toHex(msg) { - var res = ''; - for (var i = 0; i < msg.length; i++) - res += zero2(msg[i].toString(16)); - return res; - } - var toHex_1 = toHex; - - function htonl(w) { - var res = (w >>> 24) | - ((w >>> 8) & 0xff00) | - ((w << 8) & 0xff0000) | - ((w & 0xff) << 24); - return res >>> 0; - } - var htonl_1 = htonl; - - function toHex32(msg, endian) { - var res = ''; - for (var i = 0; i < msg.length; i++) { - var w = msg[i]; - if (endian === 'little') - w = htonl(w); - res += zero8(w.toString(16)); - } - return res; - } - var toHex32_1 = toHex32; - - function zero2(word) { - if (word.length === 1) - return '0' + word; - else - return word; - } - var zero2_1 = zero2; - - function zero8(word) { - if (word.length === 7) - return '0' + word; - else if (word.length === 6) - return '00' + word; - else if (word.length === 5) - return '000' + word; - else if (word.length === 4) - return '0000' + word; - else if (word.length === 3) - return '00000' + word; - else if (word.length === 2) - return '000000' + word; - else if (word.length === 1) - return '0000000' + word; - else - return word; - } - var zero8_1 = zero8; - - function join32(msg, start, end, endian) { - var len = end - start; - minimalisticAssert(len % 4 === 0); - var res = new Array(len / 4); - for (var i = 0, k = start; i < res.length; i++, k += 4) { - var w; - if (endian === 'big') - w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3]; - else - w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k]; - res[i] = w >>> 0; - } - return res; - } - var join32_1 = join32; - - function split32(msg, endian) { - var res = new Array(msg.length * 4); - for (var i = 0, k = 0; i < msg.length; i++, k += 4) { - var m = msg[i]; - if (endian === 'big') { - res[k] = m >>> 24; - res[k + 1] = (m >>> 16) & 0xff; - res[k + 2] = (m >>> 8) & 0xff; - res[k + 3] = m & 0xff; - } else { - res[k + 3] = m >>> 24; - res[k + 2] = (m >>> 16) & 0xff; - res[k + 1] = (m >>> 8) & 0xff; - res[k] = m & 0xff; - } - } - return res; - } - var split32_1 = split32; - - function rotr32(w, b) { - return (w >>> b) | (w << (32 - b)); - } - var rotr32_1 = rotr32; - - function rotl32(w, b) { - return (w << b) | (w >>> (32 - b)); - } - var rotl32_1 = rotl32; - - function sum32(a, b) { - return (a + b) >>> 0; - } - var sum32_1 = sum32; - - function sum32_3(a, b, c) { - return (a + b + c) >>> 0; - } - var sum32_3_1 = sum32_3; - - function sum32_4(a, b, c, d) { - return (a + b + c + d) >>> 0; - } - var sum32_4_1 = sum32_4; - - function sum32_5(a, b, c, d, e) { - return (a + b + c + d + e) >>> 0; - } - var sum32_5_1 = sum32_5; - - function sum64(buf, pos, ah, al) { - var bh = buf[pos]; - var bl = buf[pos + 1]; - - var lo = (al + bl) >>> 0; - var hi = (lo < al ? 1 : 0) + ah + bh; - buf[pos] = hi >>> 0; - buf[pos + 1] = lo; - } - var sum64_1 = sum64; - - function sum64_hi(ah, al, bh, bl) { - var lo = (al + bl) >>> 0; - var hi = (lo < al ? 1 : 0) + ah + bh; - return hi >>> 0; - } - var sum64_hi_1 = sum64_hi; - - function sum64_lo(ah, al, bh, bl) { - var lo = al + bl; - return lo >>> 0; - } - var sum64_lo_1 = sum64_lo; - - function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) { - var carry = 0; - var lo = al; - lo = (lo + bl) >>> 0; - carry += lo < al ? 1 : 0; - lo = (lo + cl) >>> 0; - carry += lo < cl ? 1 : 0; - lo = (lo + dl) >>> 0; - carry += lo < dl ? 1 : 0; - - var hi = ah + bh + ch + dh + carry; - return hi >>> 0; - } - var sum64_4_hi_1 = sum64_4_hi; - - function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) { - var lo = al + bl + cl + dl; - return lo >>> 0; - } - var sum64_4_lo_1 = sum64_4_lo; - - function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { - var carry = 0; - var lo = al; - lo = (lo + bl) >>> 0; - carry += lo < al ? 1 : 0; - lo = (lo + cl) >>> 0; - carry += lo < cl ? 1 : 0; - lo = (lo + dl) >>> 0; - carry += lo < dl ? 1 : 0; - lo = (lo + el) >>> 0; - carry += lo < el ? 1 : 0; - - var hi = ah + bh + ch + dh + eh + carry; - return hi >>> 0; - } - var sum64_5_hi_1 = sum64_5_hi; - - function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { - var lo = al + bl + cl + dl + el; - - return lo >>> 0; - } - var sum64_5_lo_1 = sum64_5_lo; - - function rotr64_hi(ah, al, num) { - var r = (al << (32 - num)) | (ah >>> num); - return r >>> 0; - } - var rotr64_hi_1 = rotr64_hi; - - function rotr64_lo(ah, al, num) { - var r = (ah << (32 - num)) | (al >>> num); - return r >>> 0; - } - var rotr64_lo_1 = rotr64_lo; - - function shr64_hi(ah, al, num) { - return ah >>> num; - } - var shr64_hi_1 = shr64_hi; - - function shr64_lo(ah, al, num) { - var r = (ah << (32 - num)) | (al >>> num); - return r >>> 0; - } - var shr64_lo_1 = shr64_lo; - - var utils = { - inherits: inherits_1, - toArray: toArray_1, - toHex: toHex_1, - htonl: htonl_1, - toHex32: toHex32_1, - zero2: zero2_1, - zero8: zero8_1, - join32: join32_1, - split32: split32_1, - rotr32: rotr32_1, - rotl32: rotl32_1, - sum32: sum32_1, - sum32_3: sum32_3_1, - sum32_4: sum32_4_1, - sum32_5: sum32_5_1, - sum64: sum64_1, - sum64_hi: sum64_hi_1, - sum64_lo: sum64_lo_1, - sum64_4_hi: sum64_4_hi_1, - sum64_4_lo: sum64_4_lo_1, - sum64_5_hi: sum64_5_hi_1, - sum64_5_lo: sum64_5_lo_1, - rotr64_hi: rotr64_hi_1, - rotr64_lo: rotr64_lo_1, - shr64_hi: shr64_hi_1, - shr64_lo: shr64_lo_1 - }; - - function BlockHash() { - this.pending = null; - this.pendingTotal = 0; - this.blockSize = this.constructor.blockSize; - this.outSize = this.constructor.outSize; - this.hmacStrength = this.constructor.hmacStrength; - this.padLength = this.constructor.padLength / 8; - this.endian = 'big'; - - this._delta8 = this.blockSize / 8; - this._delta32 = this.blockSize / 32; - } - var BlockHash_1 = BlockHash; - - BlockHash.prototype.update = function update(msg, enc) { - // Convert message to array, pad it, and join into 32bit blocks - msg = utils.toArray(msg, enc); - if (!this.pending) - this.pending = msg; - else - this.pending = this.pending.concat(msg); - this.pendingTotal += msg.length; - - // Enough data, try updating - if (this.pending.length >= this._delta8) { - msg = this.pending; - - // Process pending data in blocks - var r = msg.length % this._delta8; - this.pending = msg.slice(msg.length - r, msg.length); - if (this.pending.length === 0) - this.pending = null; - - msg = utils.join32(msg, 0, msg.length - r, this.endian); - for (var i = 0; i < msg.length; i += this._delta32) - this._update(msg, i, i + this._delta32); - } - - return this; - }; - - BlockHash.prototype.digest = function digest(enc) { - this.update(this._pad()); - minimalisticAssert(this.pending === null); - - return this._digest(enc); - }; - - BlockHash.prototype._pad = function pad() { - var len = this.pendingTotal; - var bytes = this._delta8; - var k = bytes - ((len + this.padLength) % bytes); - var res = new Array(k + this.padLength); - res[0] = 0x80; - for (var i = 1; i < k; i++) - res[i] = 0; - - // Append length - len <<= 3; - if (this.endian === 'big') { - for (var t = 8; t < this.padLength; t++) - res[i++] = 0; - - res[i++] = 0; - res[i++] = 0; - res[i++] = 0; - res[i++] = 0; - res[i++] = (len >>> 24) & 0xff; - res[i++] = (len >>> 16) & 0xff; - res[i++] = (len >>> 8) & 0xff; - res[i++] = len & 0xff; - } else { - res[i++] = len & 0xff; - res[i++] = (len >>> 8) & 0xff; - res[i++] = (len >>> 16) & 0xff; - res[i++] = (len >>> 24) & 0xff; - res[i++] = 0; - res[i++] = 0; - res[i++] = 0; - res[i++] = 0; - - for (t = 8; t < this.padLength; t++) - res[i++] = 0; - } - - return res; - }; - - var common = { - BlockHash: BlockHash_1 - }; - - var rotr32$1 = utils.rotr32; - - function ft_1(s, x, y, z) { - if (s === 0) - return ch32(x, y, z); - if (s === 1 || s === 3) - return p32(x, y, z); - if (s === 2) - return maj32(x, y, z); - } - var ft_1_1 = ft_1; - - function ch32(x, y, z) { - return (x & y) ^ ((~x) & z); - } - var ch32_1 = ch32; - - function maj32(x, y, z) { - return (x & y) ^ (x & z) ^ (y & z); - } - var maj32_1 = maj32; - - function p32(x, y, z) { - return x ^ y ^ z; - } - var p32_1 = p32; - - function s0_256(x) { - return rotr32$1(x, 2) ^ rotr32$1(x, 13) ^ rotr32$1(x, 22); - } - var s0_256_1 = s0_256; - - function s1_256(x) { - return rotr32$1(x, 6) ^ rotr32$1(x, 11) ^ rotr32$1(x, 25); - } - var s1_256_1 = s1_256; - - function g0_256(x) { - return rotr32$1(x, 7) ^ rotr32$1(x, 18) ^ (x >>> 3); - } - var g0_256_1 = g0_256; - - function g1_256(x) { - return rotr32$1(x, 17) ^ rotr32$1(x, 19) ^ (x >>> 10); - } - var g1_256_1 = g1_256; - - var common$1 = { - ft_1: ft_1_1, - ch32: ch32_1, - maj32: maj32_1, - p32: p32_1, - s0_256: s0_256_1, - s1_256: s1_256_1, - g0_256: g0_256_1, - g1_256: g1_256_1 - }; - - var sum32$1 = utils.sum32; - var sum32_4$1 = utils.sum32_4; - var sum32_5$1 = utils.sum32_5; - var ch32$1 = common$1.ch32; - var maj32$1 = common$1.maj32; - var s0_256$1 = common$1.s0_256; - var s1_256$1 = common$1.s1_256; - var g0_256$1 = common$1.g0_256; - var g1_256$1 = common$1.g1_256; - - var BlockHash$1 = common.BlockHash; - - var sha256_K = [ - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 - ]; - - function SHA256() { - if (!(this instanceof SHA256)) - return new SHA256(); - - BlockHash$1.call(this); - this.h = [ - 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, - 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 - ]; - this.k = sha256_K; - this.W = new Array(64); - } - utils.inherits(SHA256, BlockHash$1); - var _256 = SHA256; - - SHA256.blockSize = 512; - SHA256.outSize = 256; - SHA256.hmacStrength = 192; - SHA256.padLength = 64; - - SHA256.prototype._update = function _update(msg, start) { - var W = this.W; - - for (var i = 0; i < 16; i++) - W[i] = msg[start + i]; - for (; i < W.length; i++) - W[i] = sum32_4$1(g1_256$1(W[i - 2]), W[i - 7], g0_256$1(W[i - 15]), W[i - 16]); - - var a = this.h[0]; - var b = this.h[1]; - var c = this.h[2]; - var d = this.h[3]; - var e = this.h[4]; - var f = this.h[5]; - var g = this.h[6]; - var h = this.h[7]; - - minimalisticAssert(this.k.length === W.length); - for (i = 0; i < W.length; i++) { - var T1 = sum32_5$1(h, s1_256$1(e), ch32$1(e, f, g), this.k[i], W[i]); - var T2 = sum32$1(s0_256$1(a), maj32$1(a, b, c)); - h = g; - g = f; - f = e; - e = sum32$1(d, T1); - d = c; - c = b; - b = a; - a = sum32$1(T1, T2); - } - - this.h[0] = sum32$1(this.h[0], a); - this.h[1] = sum32$1(this.h[1], b); - this.h[2] = sum32$1(this.h[2], c); - this.h[3] = sum32$1(this.h[3], d); - this.h[4] = sum32$1(this.h[4], e); - this.h[5] = sum32$1(this.h[5], f); - this.h[6] = sum32$1(this.h[6], g); - this.h[7] = sum32$1(this.h[7], h); - }; - - SHA256.prototype._digest = function digest(enc) { - if (enc === 'hex') - return utils.toHex32(this.h, 'big'); - else - return utils.split32(this.h, 'big'); - }; - - var charToInteger = {}; - var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; - for (var i = 0; i < chars.length; i++) { - charToInteger[chars.charCodeAt(i)] = i; - } - function decode(mappings) { - var generatedCodeColumn = 0; // first field - var sourceFileIndex = 0; // second field - var sourceCodeLine = 0; // third field - var sourceCodeColumn = 0; // fourth field - var nameIndex = 0; // fifth field - var decoded = []; - var line = []; - var segment = []; - for (var i = 0, j = 0, shift = 0, value = 0; i < mappings.length; i++) { - var c = mappings.charCodeAt(i); - if (c === 44) { - if (segment.length) - line.push(segment); - segment = []; - j = 0; - } - else if (c === 59) { - if (segment.length) - line.push(segment); - segment = []; - j = 0; - decoded.push(line); - line = []; - generatedCodeColumn = 0; - } - else { - var integer = charToInteger[c]; - if (integer === undefined) { - throw new Error('Invalid character (' + String.fromCharCode(c) + ')'); - } - var hasContinuationBit = integer & 32; - integer &= 31; - value += integer << shift; - if (hasContinuationBit) { - shift += 5; - } - else { - var shouldNegate = value & 1; - value >>= 1; - var num = shouldNegate ? -value : value; - if (j == 0) { - generatedCodeColumn += num; - segment.push(generatedCodeColumn); - } - else if (j === 1) { - sourceFileIndex += num; - segment.push(sourceFileIndex); - } - else if (j === 2) { - sourceCodeLine += num; - segment.push(sourceCodeLine); - } - else if (j === 3) { - sourceCodeColumn += num; - segment.push(sourceCodeColumn); - } - else if (j === 4) { - nameIndex += num; - segment.push(nameIndex); - } - j++; - value = shift = 0; // reset - } - } - } - if (segment.length) - line.push(segment); - decoded.push(line); - return decoded; - } - function encode(decoded) { - var sourceFileIndex = 0; // second field - var sourceCodeLine = 0; // third field - var sourceCodeColumn = 0; // fourth field - var nameIndex = 0; // fifth field - var mappings = ''; - for (var i = 0; i < decoded.length; i++) { - var line = decoded[i]; - if (i > 0) - mappings += ';'; - if (line.length === 0) - continue; - var generatedCodeColumn = 0; // first field - var lineMappings = []; - for (var _i = 0, line_1 = line; _i < line_1.length; _i++) { - var segment = line_1[_i]; - var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn); - generatedCodeColumn = segment[0]; - if (segment.length > 1) { - segmentMappings += - encodeInteger(segment[1] - sourceFileIndex) + - encodeInteger(segment[2] - sourceCodeLine) + - encodeInteger(segment[3] - sourceCodeColumn); - sourceFileIndex = segment[1]; - sourceCodeLine = segment[2]; - sourceCodeColumn = segment[3]; - } - if (segment.length === 5) { - segmentMappings += encodeInteger(segment[4] - nameIndex); - nameIndex = segment[4]; - } - lineMappings.push(segmentMappings); - } - mappings += lineMappings.join(','); - } - return mappings; - } - function encodeInteger(num) { - var result = ''; - num = num < 0 ? (-num << 1) | 1 : num << 1; - do { - var clamped = num & 31; - num >>= 5; - if (num > 0) { - clamped |= 32; - } - result += chars[clamped]; - } while (num > 0); - return result; - } - - var Chunk = function Chunk(start, end, content) { - this.start = start; - this.end = end; - this.original = content; - - this.intro = ''; - this.outro = ''; - - this.content = content; - this.storeName = false; - this.edited = false; - - // we make these non-enumerable, for sanity while debugging - Object.defineProperties(this, { - previous: { writable: true, value: null }, - next: { writable: true, value: null } - }); - }; - - Chunk.prototype.appendLeft = function appendLeft (content) { - this.outro += content; - }; - - Chunk.prototype.appendRight = function appendRight (content) { - this.intro = this.intro + content; - }; - - Chunk.prototype.clone = function clone () { - var chunk = new Chunk(this.start, this.end, this.original); - - chunk.intro = this.intro; - chunk.outro = this.outro; - chunk.content = this.content; - chunk.storeName = this.storeName; - chunk.edited = this.edited; - - return chunk; - }; - - Chunk.prototype.contains = function contains (index) { - return this.start < index && index < this.end; - }; - - Chunk.prototype.eachNext = function eachNext (fn) { - var chunk = this; - while (chunk) { - fn(chunk); - chunk = chunk.next; - } - }; - - Chunk.prototype.eachPrevious = function eachPrevious (fn) { - var chunk = this; - while (chunk) { - fn(chunk); - chunk = chunk.previous; - } - }; - - Chunk.prototype.edit = function edit (content, storeName, contentOnly) { - this.content = content; - if (!contentOnly) { - this.intro = ''; - this.outro = ''; - } - this.storeName = storeName; - - this.edited = true; - - return this; - }; - - Chunk.prototype.prependLeft = function prependLeft (content) { - this.outro = content + this.outro; - }; - - Chunk.prototype.prependRight = function prependRight (content) { - this.intro = content + this.intro; - }; - - Chunk.prototype.split = function split (index) { - var sliceIndex = index - this.start; - - var originalBefore = this.original.slice(0, sliceIndex); - var originalAfter = this.original.slice(sliceIndex); - - this.original = originalBefore; - - var newChunk = new Chunk(index, this.end, originalAfter); - newChunk.outro = this.outro; - this.outro = ''; - - this.end = index; - - if (this.edited) { - // TODO is this block necessary?... - newChunk.edit('', false); - this.content = ''; - } else { - this.content = originalBefore; - } - - newChunk.next = this.next; - if (newChunk.next) { newChunk.next.previous = newChunk; } - newChunk.previous = this; - this.next = newChunk; - - return newChunk; - }; - - Chunk.prototype.toString = function toString () { - return this.intro + this.content + this.outro; - }; - - Chunk.prototype.trimEnd = function trimEnd (rx) { - this.outro = this.outro.replace(rx, ''); - if (this.outro.length) { return true; } - - var trimmed = this.content.replace(rx, ''); - - if (trimmed.length) { - if (trimmed !== this.content) { - this.split(this.start + trimmed.length).edit('', undefined, true); - } - return true; - - } else { - this.edit('', undefined, true); - - this.intro = this.intro.replace(rx, ''); - if (this.intro.length) { return true; } - } - }; - - Chunk.prototype.trimStart = function trimStart (rx) { - this.intro = this.intro.replace(rx, ''); - if (this.intro.length) { return true; } - - var trimmed = this.content.replace(rx, ''); - - if (trimmed.length) { - if (trimmed !== this.content) { - this.split(this.end - trimmed.length); - this.edit('', undefined, true); - } - return true; - - } else { - this.edit('', undefined, true); - - this.outro = this.outro.replace(rx, ''); - if (this.outro.length) { return true; } - } - }; - - var btoa = function () { - throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.'); - }; - if (typeof window !== 'undefined' && typeof window.btoa === 'function') { - btoa = window.btoa; - } else if (typeof Buffer === 'function') { - btoa = function (str) { return new Buffer(str).toString('base64'); }; - } - - var SourceMap = function SourceMap(properties) { - this.version = 3; - this.file = properties.file; - this.sources = properties.sources; - this.sourcesContent = properties.sourcesContent; - this.names = properties.names; - this.mappings = encode(properties.mappings); - }; - - SourceMap.prototype.toString = function toString () { - return JSON.stringify(this); - }; - - SourceMap.prototype.toUrl = function toUrl () { - return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString()); - }; - - function guessIndent(code) { - var lines = code.split('\n'); - - var tabbed = lines.filter(function (line) { return /^\t+/.test(line); }); - var spaced = lines.filter(function (line) { return /^ {2,}/.test(line); }); - - if (tabbed.length === 0 && spaced.length === 0) { - return null; - } - - // More lines tabbed than spaced? Assume tabs, and - // default to tabs in the case of a tie (or nothing - // to go on) - if (tabbed.length >= spaced.length) { - return '\t'; - } - - // Otherwise, we need to guess the multiple - var min = spaced.reduce(function (previous, current) { - var numSpaces = /^ +/.exec(current)[0].length; - return Math.min(numSpaces, previous); - }, Infinity); - - return new Array(min + 1).join(' '); - } - - function getRelativePath(from, to) { - var fromParts = from.split(/[/\\]/); - var toParts = to.split(/[/\\]/); - - fromParts.pop(); // get dirname - - while (fromParts[0] === toParts[0]) { - fromParts.shift(); - toParts.shift(); - } - - if (fromParts.length) { - var i = fromParts.length; - while (i--) { fromParts[i] = '..'; } - } - - return fromParts.concat(toParts).join('/'); - } - - var toString = Object.prototype.toString; - - function isObject(thing) { - return toString.call(thing) === '[object Object]'; - } - - function getLocator(source) { - var originalLines = source.split('\n'); - var lineOffsets = []; - - for (var i = 0, pos = 0; i < originalLines.length; i++) { - lineOffsets.push(pos); - pos += originalLines[i].length + 1; - } - - return function locate(index) { - var i = 0; - var j = lineOffsets.length; - while (i < j) { - var m = (i + j) >> 1; - if (index < lineOffsets[m]) { - j = m; - } else { - i = m + 1; - } - } - var line = i - 1; - var column = index - lineOffsets[line]; - return { line: line, column: column }; - }; - } - - var Mappings = function Mappings(hires) { - this.hires = hires; - this.generatedCodeLine = 0; - this.generatedCodeColumn = 0; - this.raw = []; - this.rawSegments = this.raw[this.generatedCodeLine] = []; - this.pending = null; - }; - - Mappings.prototype.addEdit = function addEdit (sourceIndex, content, loc, nameIndex) { - if (content.length) { - var segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column]; - if (nameIndex >= 0) { - segment.push(nameIndex); - } - this.rawSegments.push(segment); - } else if (this.pending) { - this.rawSegments.push(this.pending); - } - - this.advance(content); - this.pending = null; - }; - - Mappings.prototype.addUneditedChunk = function addUneditedChunk (sourceIndex, chunk, original, loc, sourcemapLocations) { - var this$1 = this; - - var originalCharIndex = chunk.start; - var first = true; - - while (originalCharIndex < chunk.end) { - if (this$1.hires || first || sourcemapLocations[originalCharIndex]) { - this$1.rawSegments.push([this$1.generatedCodeColumn, sourceIndex, loc.line, loc.column]); - } - - if (original[originalCharIndex] === '\n') { - loc.line += 1; - loc.column = 0; - this$1.generatedCodeLine += 1; - this$1.raw[this$1.generatedCodeLine] = this$1.rawSegments = []; - this$1.generatedCodeColumn = 0; - } else { - loc.column += 1; - this$1.generatedCodeColumn += 1; - } - - originalCharIndex += 1; - first = false; - } - - this.pending = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column]; - }; - - Mappings.prototype.advance = function advance (str) { - var this$1 = this; - - if (!str) { return; } - - var lines = str.split('\n'); - - if (lines.length > 1) { - for (var i = 0; i < lines.length - 1; i++) { - this$1.generatedCodeLine++; - this$1.raw[this$1.generatedCodeLine] = this$1.rawSegments = []; - } - this.generatedCodeColumn = 0; - } - - this.generatedCodeColumn += lines[lines.length - 1].length; - }; - - var n = '\n'; - - var warned = { - insertLeft: false, - insertRight: false, - storeName: false - }; - - var MagicString = function MagicString(string, options) { - if ( options === void 0 ) options = {}; - - var chunk = new Chunk(0, string.length, string); - - Object.defineProperties(this, { - original: { writable: true, value: string }, - outro: { writable: true, value: '' }, - intro: { writable: true, value: '' }, - firstChunk: { writable: true, value: chunk }, - lastChunk: { writable: true, value: chunk }, - lastSearchedChunk: { writable: true, value: chunk }, - byStart: { writable: true, value: {} }, - byEnd: { writable: true, value: {} }, - filename: { writable: true, value: options.filename }, - indentExclusionRanges: { writable: true, value: options.indentExclusionRanges }, - sourcemapLocations: { writable: true, value: {} }, - storedNames: { writable: true, value: {} }, - indentStr: { writable: true, value: guessIndent(string) } - }); - - this.byStart[0] = chunk; - this.byEnd[string.length] = chunk; - }; - - MagicString.prototype.addSourcemapLocation = function addSourcemapLocation (char) { - this.sourcemapLocations[char] = true; - }; - - MagicString.prototype.append = function append (content) { - if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); } - - this.outro += content; - return this; - }; - - MagicString.prototype.appendLeft = function appendLeft (index, content) { - if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); } - - this._split(index); - - var chunk = this.byEnd[index]; - - if (chunk) { - chunk.appendLeft(content); - } else { - this.intro += content; - } - return this; - }; - - MagicString.prototype.appendRight = function appendRight (index, content) { - if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); } - - this._split(index); - - var chunk = this.byStart[index]; - - if (chunk) { - chunk.appendRight(content); - } else { - this.outro += content; - } - return this; - }; - - MagicString.prototype.clone = function clone () { - var cloned = new MagicString(this.original, { filename: this.filename }); - - var originalChunk = this.firstChunk; - var clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone()); - - while (originalChunk) { - cloned.byStart[clonedChunk.start] = clonedChunk; - cloned.byEnd[clonedChunk.end] = clonedChunk; - - var nextOriginalChunk = originalChunk.next; - var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone(); - - if (nextClonedChunk) { - clonedChunk.next = nextClonedChunk; - nextClonedChunk.previous = clonedChunk; - - clonedChunk = nextClonedChunk; - } - - originalChunk = nextOriginalChunk; - } - - cloned.lastChunk = clonedChunk; - - if (this.indentExclusionRanges) { - cloned.indentExclusionRanges = this.indentExclusionRanges.slice(); - } - - Object.keys(this.sourcemapLocations).forEach(function (loc) { - cloned.sourcemapLocations[loc] = true; - }); - - return cloned; - }; - - MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) { - var this$1 = this; - - options = options || {}; - - var sourceIndex = 0; - var names = Object.keys(this.storedNames); - var mappings = new Mappings(options.hires); - - var locate = getLocator(this.original); - - if (this.intro) { - mappings.advance(this.intro); - } - - this.firstChunk.eachNext(function (chunk) { - var loc = locate(chunk.start); - - if (chunk.intro.length) { mappings.advance(chunk.intro); } - - if (chunk.edited) { - mappings.addEdit( - sourceIndex, - chunk.content, - loc, - chunk.storeName ? names.indexOf(chunk.original) : -1 - ); - } else { - mappings.addUneditedChunk(sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations); - } - - if (chunk.outro.length) { mappings.advance(chunk.outro); } - }); - - return { - file: options.file ? options.file.split(/[/\\]/).pop() : null, - sources: [options.source ? getRelativePath(options.file || '', options.source) : null], - sourcesContent: options.includeContent ? [this.original] : [null], - names: names, - mappings: mappings.raw - }; - }; - - MagicString.prototype.generateMap = function generateMap (options) { - return new SourceMap(this.generateDecodedMap(options)); - }; - - MagicString.prototype.getIndentString = function getIndentString () { - return this.indentStr === null ? '\t' : this.indentStr; - }; - - MagicString.prototype.indent = function indent (indentStr, options) { - var this$1 = this; - - var pattern = /^[^\r\n]/gm; - - if (isObject(indentStr)) { - options = indentStr; - indentStr = undefined; - } - - indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t'; - - if (indentStr === '') { return this; } // noop - - options = options || {}; - - // Process exclusion ranges - var isExcluded = {}; - - if (options.exclude) { - var exclusions = - typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude; - exclusions.forEach(function (exclusion) { - for (var i = exclusion[0]; i < exclusion[1]; i += 1) { - isExcluded[i] = true; - } - }); - } - - var shouldIndentNextCharacter = options.indentStart !== false; - var replacer = function (match) { - if (shouldIndentNextCharacter) { return ("" + indentStr + match); } - shouldIndentNextCharacter = true; - return match; - }; - - this.intro = this.intro.replace(pattern, replacer); - - var charIndex = 0; - var chunk = this.firstChunk; - - while (chunk) { - var end = chunk.end; - - if (chunk.edited) { - if (!isExcluded[charIndex]) { - chunk.content = chunk.content.replace(pattern, replacer); - - if (chunk.content.length) { - shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n'; - } - } - } else { - charIndex = chunk.start; - - while (charIndex < end) { - if (!isExcluded[charIndex]) { - var char = this$1.original[charIndex]; - - if (char === '\n') { - shouldIndentNextCharacter = true; - } else if (char !== '\r' && shouldIndentNextCharacter) { - shouldIndentNextCharacter = false; - - if (charIndex === chunk.start) { - chunk.prependRight(indentStr); - } else { - this$1._splitChunk(chunk, charIndex); - chunk = chunk.next; - chunk.prependRight(indentStr); - } - } - } - - charIndex += 1; - } - } - - charIndex = chunk.end; - chunk = chunk.next; - } - - this.outro = this.outro.replace(pattern, replacer); - - return this; - }; - - MagicString.prototype.insert = function insert () { - throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'); - }; - - MagicString.prototype.insertLeft = function insertLeft (index, content) { - if (!warned.insertLeft) { - console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console - warned.insertLeft = true; - } - - return this.appendLeft(index, content); - }; - - MagicString.prototype.insertRight = function insertRight (index, content) { - if (!warned.insertRight) { - console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console - warned.insertRight = true; - } - - return this.prependRight(index, content); - }; - - MagicString.prototype.move = function move (start, end, index) { - if (index >= start && index <= end) { throw new Error('Cannot move a selection inside itself'); } - - this._split(start); - this._split(end); - this._split(index); - - var first = this.byStart[start]; - var last = this.byEnd[end]; - - var oldLeft = first.previous; - var oldRight = last.next; - - var newRight = this.byStart[index]; - if (!newRight && last === this.lastChunk) { return this; } - var newLeft = newRight ? newRight.previous : this.lastChunk; - - if (oldLeft) { oldLeft.next = oldRight; } - if (oldRight) { oldRight.previous = oldLeft; } - - if (newLeft) { newLeft.next = first; } - if (newRight) { newRight.previous = last; } - - if (!first.previous) { this.firstChunk = last.next; } - if (!last.next) { - this.lastChunk = first.previous; - this.lastChunk.next = null; - } - - first.previous = newLeft; - last.next = newRight || null; - - if (!newLeft) { this.firstChunk = first; } - if (!newRight) { this.lastChunk = last; } - return this; - }; - - MagicString.prototype.overwrite = function overwrite (start, end, content, options) { - var this$1 = this; - - if (typeof content !== 'string') { throw new TypeError('replacement content must be a string'); } - - while (start < 0) { start += this$1.original.length; } - while (end < 0) { end += this$1.original.length; } - - if (end > this.original.length) { throw new Error('end is out of bounds'); } - if (start === end) - { throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); } - - this._split(start); - this._split(end); - - if (options === true) { - if (!warned.storeName) { - console.warn('The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'); // eslint-disable-line no-console - warned.storeName = true; - } - - options = { storeName: true }; - } - var storeName = options !== undefined ? options.storeName : false; - var contentOnly = options !== undefined ? options.contentOnly : false; - - if (storeName) { - var original = this.original.slice(start, end); - this.storedNames[original] = true; - } - - var first = this.byStart[start]; - var last = this.byEnd[end]; - - if (first) { - if (end > first.end && first.next !== this.byStart[first.end]) { - throw new Error('Cannot overwrite across a split point'); - } - - first.edit(content, storeName, contentOnly); - - if (first !== last) { - var chunk = first.next; - while (chunk !== last) { - chunk.edit('', false); - chunk = chunk.next; - } - - chunk.edit('', false); - } - } else { - // must be inserting at the end - var newChunk = new Chunk(start, end, '').edit(content, storeName); - - // TODO last chunk in the array may not be the last chunk, if it's moved... - last.next = newChunk; - newChunk.previous = last; - } - return this; - }; - - MagicString.prototype.prepend = function prepend (content) { - if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); } - - this.intro = content + this.intro; - return this; - }; - - MagicString.prototype.prependLeft = function prependLeft (index, content) { - if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); } - - this._split(index); - - var chunk = this.byEnd[index]; - - if (chunk) { - chunk.prependLeft(content); - } else { - this.intro = content + this.intro; - } - return this; - }; - - MagicString.prototype.prependRight = function prependRight (index, content) { - if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); } - - this._split(index); - - var chunk = this.byStart[index]; - - if (chunk) { - chunk.prependRight(content); - } else { - this.outro = content + this.outro; - } - return this; - }; - - MagicString.prototype.remove = function remove (start, end) { - var this$1 = this; - - while (start < 0) { start += this$1.original.length; } - while (end < 0) { end += this$1.original.length; } - - if (start === end) { return this; } - - if (start < 0 || end > this.original.length) { throw new Error('Character is out of bounds'); } - if (start > end) { throw new Error('end must be greater than start'); } - - this._split(start); - this._split(end); - - var chunk = this.byStart[start]; - - while (chunk) { - chunk.intro = ''; - chunk.outro = ''; - chunk.edit(''); - - chunk = end > chunk.end ? this$1.byStart[chunk.end] : null; - } - return this; - }; - - MagicString.prototype.lastChar = function lastChar () { - if (this.outro.length) - { return this.outro[this.outro.length - 1]; } - var chunk = this.lastChunk; - do { - if (chunk.outro.length) - { return chunk.outro[chunk.outro.length - 1]; } - if (chunk.content.length) - { return chunk.content[chunk.content.length - 1]; } - if (chunk.intro.length) - { return chunk.intro[chunk.intro.length - 1]; } - } while (chunk = chunk.previous); - if (this.intro.length) - { return this.intro[this.intro.length - 1]; } - return ''; - }; - - MagicString.prototype.lastLine = function lastLine () { - var lineIndex = this.outro.lastIndexOf(n); - if (lineIndex !== -1) - { return this.outro.substr(lineIndex + 1); } - var lineStr = this.outro; - var chunk = this.lastChunk; - do { - if (chunk.outro.length > 0) { - lineIndex = chunk.outro.lastIndexOf(n); - if (lineIndex !== -1) - { return chunk.outro.substr(lineIndex + 1) + lineStr; } - lineStr = chunk.outro + lineStr; - } - - if (chunk.content.length > 0) { - lineIndex = chunk.content.lastIndexOf(n); - if (lineIndex !== -1) - { return chunk.content.substr(lineIndex + 1) + lineStr; } - lineStr = chunk.content + lineStr; - } - - if (chunk.intro.length > 0) { - lineIndex = chunk.intro.lastIndexOf(n); - if (lineIndex !== -1) - { return chunk.intro.substr(lineIndex + 1) + lineStr; } - lineStr = chunk.intro + lineStr; - } - } while (chunk = chunk.previous); - lineIndex = this.intro.lastIndexOf(n); - if (lineIndex !== -1) - { return this.intro.substr(lineIndex + 1) + lineStr; } - return this.intro + lineStr; - }; - - MagicString.prototype.slice = function slice (start, end) { - var this$1 = this; - if ( start === void 0 ) start = 0; - if ( end === void 0 ) end = this.original.length; - - while (start < 0) { start += this$1.original.length; } - while (end < 0) { end += this$1.original.length; } - - var result = ''; - - // find start chunk - var chunk = this.firstChunk; - while (chunk && (chunk.start > start || chunk.end <= start)) { - // found end chunk before start - if (chunk.start < end && chunk.end >= end) { - return result; - } - - chunk = chunk.next; - } - - if (chunk && chunk.edited && chunk.start !== start) - { throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); } - - var startChunk = chunk; - while (chunk) { - if (chunk.intro && (startChunk !== chunk || chunk.start === start)) { - result += chunk.intro; - } - - var containsEnd = chunk.start < end && chunk.end >= end; - if (containsEnd && chunk.edited && chunk.end !== end) - { throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); } - - var sliceStart = startChunk === chunk ? start - chunk.start : 0; - var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length; - - result += chunk.content.slice(sliceStart, sliceEnd); - - if (chunk.outro && (!containsEnd || chunk.end === end)) { - result += chunk.outro; - } - - if (containsEnd) { - break; - } - - chunk = chunk.next; - } - - return result; - }; - - // TODO deprecate this? not really very useful - MagicString.prototype.snip = function snip (start, end) { - var clone = this.clone(); - clone.remove(0, start); - clone.remove(end, clone.original.length); - - return clone; - }; - - MagicString.prototype._split = function _split (index) { - var this$1 = this; - - if (this.byStart[index] || this.byEnd[index]) { return; } - - var chunk = this.lastSearchedChunk; - var searchForward = index > chunk.end; - - while (chunk) { - if (chunk.contains(index)) { return this$1._splitChunk(chunk, index); } - - chunk = searchForward ? this$1.byStart[chunk.end] : this$1.byEnd[chunk.start]; - } - }; - - MagicString.prototype._splitChunk = function _splitChunk (chunk, index) { - if (chunk.edited && chunk.content.length) { - // zero-length edited chunks are a special case (overlapping replacements) - var loc = getLocator(this.original)(index); - throw new Error( - ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")") - ); - } - - var newChunk = chunk.split(index); - - this.byEnd[index] = chunk; - this.byStart[index] = newChunk; - this.byEnd[newChunk.end] = newChunk; - - if (chunk === this.lastChunk) { this.lastChunk = newChunk; } - - this.lastSearchedChunk = chunk; - return true; - }; - - MagicString.prototype.toString = function toString () { - var str = this.intro; - - var chunk = this.firstChunk; - while (chunk) { - str += chunk.toString(); - chunk = chunk.next; - } - - return str + this.outro; - }; - - MagicString.prototype.isEmpty = function isEmpty () { - var chunk = this.firstChunk; - do { - if (chunk.intro.length && chunk.intro.trim() || - chunk.content.length && chunk.content.trim() || - chunk.outro.length && chunk.outro.trim()) - { return false; } - } while (chunk = chunk.next); - return true; - }; - - MagicString.prototype.length = function length () { - var chunk = this.firstChunk; - var length = 0; - do { - length += chunk.intro.length + chunk.content.length + chunk.outro.length; - } while (chunk = chunk.next); - return length; - }; - - MagicString.prototype.trimLines = function trimLines () { - return this.trim('[\\r\\n]'); - }; - - MagicString.prototype.trim = function trim (charType) { - return this.trimStart(charType).trimEnd(charType); - }; - - MagicString.prototype.trimEndAborted = function trimEndAborted (charType) { - var this$1 = this; - - var rx = new RegExp((charType || '\\s') + '+$'); - - this.outro = this.outro.replace(rx, ''); - if (this.outro.length) { return true; } - - var chunk = this.lastChunk; - - do { - var end = chunk.end; - var aborted = chunk.trimEnd(rx); - - // if chunk was trimmed, we have a new lastChunk - if (chunk.end !== end) { - if (this$1.lastChunk === chunk) { - this$1.lastChunk = chunk.next; - } - - this$1.byEnd[chunk.end] = chunk; - this$1.byStart[chunk.next.start] = chunk.next; - this$1.byEnd[chunk.next.end] = chunk.next; - } - - if (aborted) { return true; } - chunk = chunk.previous; - } while (chunk); - - return false; - }; - - MagicString.prototype.trimEnd = function trimEnd (charType) { - this.trimEndAborted(charType); - return this; - }; - MagicString.prototype.trimStartAborted = function trimStartAborted (charType) { - var this$1 = this; - - var rx = new RegExp('^' + (charType || '\\s') + '+'); - - this.intro = this.intro.replace(rx, ''); - if (this.intro.length) { return true; } - - var chunk = this.firstChunk; - - do { - var end = chunk.end; - var aborted = chunk.trimStart(rx); - - if (chunk.end !== end) { - // special case... - if (chunk === this$1.lastChunk) { this$1.lastChunk = chunk.next; } - - this$1.byEnd[chunk.end] = chunk; - this$1.byStart[chunk.next.start] = chunk.next; - this$1.byEnd[chunk.next.end] = chunk.next; - } - - if (aborted) { return true; } - chunk = chunk.next; - } while (chunk); - - return false; - }; - - MagicString.prototype.trimStart = function trimStart (charType) { - this.trimStartAborted(charType); - return this; - }; - - var hasOwnProp = Object.prototype.hasOwnProperty; - - var Bundle = function Bundle(options) { - if ( options === void 0 ) options = {}; - - this.intro = options.intro || ''; - this.separator = options.separator !== undefined ? options.separator : '\n'; - this.sources = []; - this.uniqueSources = []; - this.uniqueSourceIndexByFilename = {}; - }; - - Bundle.prototype.addSource = function addSource (source) { - if (source instanceof MagicString) { - return this.addSource({ - content: source, - filename: source.filename, - separator: this.separator - }); - } - - if (!isObject(source) || !source.content) { - throw new Error('bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`'); - } - - ['filename', 'indentExclusionRanges', 'separator'].forEach(function (option) { - if (!hasOwnProp.call(source, option)) { source[option] = source.content[option]; } - }); - - if (source.separator === undefined) { - // TODO there's a bunch of this sort of thing, needs cleaning up - source.separator = this.separator; - } - - if (source.filename) { - if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) { - this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length; - this.uniqueSources.push({ filename: source.filename, content: source.content.original }); - } else { - var uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]]; - if (source.content.original !== uniqueSource.content) { - throw new Error(("Illegal source: same filename (" + (source.filename) + "), different contents")); - } - } - } - - this.sources.push(source); - return this; - }; - - Bundle.prototype.append = function append (str, options) { - this.addSource({ - content: new MagicString(str), - separator: (options && options.separator) || '' - }); - - return this; - }; - - Bundle.prototype.clone = function clone () { - var bundle = new Bundle({ - intro: this.intro, - separator: this.separator - }); - - this.sources.forEach(function (source) { - bundle.addSource({ - filename: source.filename, - content: source.content.clone(), - separator: source.separator - }); - }); - - return bundle; - }; - - Bundle.prototype.generateDecodedMap = function generateDecodedMap (options) { - var this$1 = this; - if ( options === void 0 ) options = {}; - - var names = []; - this.sources.forEach(function (source) { - Object.keys(source.content.storedNames).forEach(function (name) { - if (!~names.indexOf(name)) { names.push(name); } - }); - }); - - var mappings = new Mappings(options.hires); - - if (this.intro) { - mappings.advance(this.intro); - } - - this.sources.forEach(function (source, i) { - if (i > 0) { - mappings.advance(this$1.separator); - } - - var sourceIndex = source.filename ? this$1.uniqueSourceIndexByFilename[source.filename] : -1; - var magicString = source.content; - var locate = getLocator(magicString.original); - - if (magicString.intro) { - mappings.advance(magicString.intro); - } - - magicString.firstChunk.eachNext(function (chunk) { - var loc = locate(chunk.start); - - if (chunk.intro.length) { mappings.advance(chunk.intro); } - - if (source.filename) { - if (chunk.edited) { - mappings.addEdit( - sourceIndex, - chunk.content, - loc, - chunk.storeName ? names.indexOf(chunk.original) : -1 - ); - } else { - mappings.addUneditedChunk( - sourceIndex, - chunk, - magicString.original, - loc, - magicString.sourcemapLocations - ); - } - } else { - mappings.advance(chunk.content); - } - - if (chunk.outro.length) { mappings.advance(chunk.outro); } - }); - - if (magicString.outro) { - mappings.advance(magicString.outro); - } - }); - - return { - file: options.file ? options.file.split(/[/\\]/).pop() : null, - sources: this.uniqueSources.map(function (source) { - return options.file ? getRelativePath(options.file, source.filename) : source.filename; - }), - sourcesContent: this.uniqueSources.map(function (source) { - return options.includeContent ? source.content : null; - }), - names: names, - mappings: mappings.raw - }; - }; - - Bundle.prototype.generateMap = function generateMap (options) { - return new SourceMap(this.generateDecodedMap(options)); - }; - - Bundle.prototype.getIndentString = function getIndentString () { - var indentStringCounts = {}; - - this.sources.forEach(function (source) { - var indentStr = source.content.indentStr; - - if (indentStr === null) { return; } - - if (!indentStringCounts[indentStr]) { indentStringCounts[indentStr] = 0; } - indentStringCounts[indentStr] += 1; - }); - - return ( - Object.keys(indentStringCounts).sort(function (a, b) { - return indentStringCounts[a] - indentStringCounts[b]; - })[0] || '\t' - ); - }; - - Bundle.prototype.indent = function indent (indentStr) { - var this$1 = this; - - if (!arguments.length) { - indentStr = this.getIndentString(); - } - - if (indentStr === '') { return this; } // noop - - var trailingNewline = !this.intro || this.intro.slice(-1) === '\n'; - - this.sources.forEach(function (source, i) { - var separator = source.separator !== undefined ? source.separator : this$1.separator; - var indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator)); - - source.content.indent(indentStr, { - exclude: source.indentExclusionRanges, - indentStart: indentStart //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator ) - }); - - trailingNewline = source.content.lastChar() === '\n'; - }); - - if (this.intro) { - this.intro = - indentStr + - this.intro.replace(/^[^\n]/gm, function (match, index) { - return index > 0 ? indentStr + match : match; - }); - } - - return this; - }; - - Bundle.prototype.prepend = function prepend (str) { - this.intro = str + this.intro; - return this; - }; - - Bundle.prototype.toString = function toString () { - var this$1 = this; - - var body = this.sources - .map(function (source, i) { - var separator = source.separator !== undefined ? source.separator : this$1.separator; - var str = (i > 0 ? separator : '') + source.content.toString(); - - return str; - }) - .join(''); - - return this.intro + body; - }; - - Bundle.prototype.isEmpty = function isEmpty () { - if (this.intro.length && this.intro.trim()) - { return false; } - if (this.sources.some(function (source) { return !source.content.isEmpty(); })) - { return false; } - return true; - }; - - Bundle.prototype.length = function length () { - return this.sources.reduce(function (length, source) { return length + source.content.length(); }, this.intro.length); - }; - - Bundle.prototype.trimLines = function trimLines () { - return this.trim('[\\r\\n]'); - }; - - Bundle.prototype.trim = function trim (charType) { - return this.trimStart(charType).trimEnd(charType); - }; - - Bundle.prototype.trimStart = function trimStart (charType) { - var this$1 = this; - - var rx = new RegExp('^' + (charType || '\\s') + '+'); - this.intro = this.intro.replace(rx, ''); - - if (!this.intro) { - var source; - var i = 0; - - do { - source = this$1.sources[i++]; - if (!source) { - break; - } - } while (!source.content.trimStartAborted(charType)); - } - - return this; - }; - - Bundle.prototype.trimEnd = function trimEnd (charType) { - var this$1 = this; - - var rx = new RegExp((charType || '\\s') + '+$'); - - var source; - var i = this.sources.length - 1; - - do { - source = this$1.sources[i--]; - if (!source) { - this$1.intro = this$1.intro.replace(rx, ''); - break; - } - } while (!source.content.trimEndAborted(charType)); - - return this; - }; - - const __assign = Object.assign || function (target) { - for (var source, i = 1; i < arguments.length; i++) { - source = arguments[i]; - for (var prop in source) { - if (Object.prototype.hasOwnProperty.call(source, prop)) { - target[prop] = source[prop]; - } - } - } - return target; - }; - - function __extends(d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - } - - var AssignmentExpression = 'AssignmentExpression'; - var BlockStatement = 'BlockStatement'; - var CallExpression = 'CallExpression'; - var ClassDeclaration = 'ClassDeclaration'; - var ExportAllDeclaration = 'ExportAllDeclaration'; - var ExportDefaultDeclaration = 'ExportDefaultDeclaration'; - var ExpressionStatement = 'ExpressionStatement'; - var FunctionDeclaration = 'FunctionDeclaration'; - var Identifier = 'Identifier'; - var ImportDefaultSpecifier = 'ImportDefaultSpecifier'; - var ImportNamespaceSpecifier = 'ImportNamespaceSpecifier'; - var Literal = 'Literal'; - var MemberExpression = 'MemberExpression'; - var Program = 'Program'; - var Property = 'Property'; - var ReturnStatement = 'ReturnStatement'; - var TemplateLiteral = 'TemplateLiteral'; - var UpdateExpression = 'UpdateExpression'; - var VariableDeclaration = 'VariableDeclaration'; - - var CallOptions = /** @class */ (function () { - function CallOptions(_a) { - var _b = _a === void 0 ? {} : _a, _c = _b.withNew, withNew = _c === void 0 ? false : _c, _d = _b.args, args = _d === void 0 ? [] : _d, _e = _b.callIdentifier, callIdentifier = _e === void 0 ? undefined : _e; - this.withNew = withNew; - this.args = args; - this.callIdentifier = callIdentifier; - } - CallOptions.create = function (callOptions) { - return new this(callOptions); - }; - CallOptions.prototype.equals = function (callOptions) { - return callOptions && this.callIdentifier === callOptions.callIdentifier; - }; - return CallOptions; - }()); - - var UNKNOWN_KEY = { UNKNOWN_KEY: true }; - var EMPTY_PATH = []; - var UNKNOWN_PATH = [UNKNOWN_KEY]; - function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions) { - if (inheritedDescriptions === void 0) { inheritedDescriptions = null; } - return Object.create(inheritedDescriptions, memberDescriptions); - } - var UNKNOWN_VALUE = { UNKNOWN_VALUE: true }; - var UNKNOWN_EXPRESSION = { - included: true, - getLiteralValueAtPath: function () { return UNKNOWN_VALUE; }, - getReturnExpressionWhenCalledAtPath: function () { return UNKNOWN_EXPRESSION; }, - hasEffectsWhenAccessedAtPath: function (path) { return path.length > 0; }, - hasEffectsWhenAssignedAtPath: function (path) { return path.length > 0; }, - hasEffectsWhenCalledAtPath: function () { return true; }, - include: function () { }, - deoptimizePath: function () { }, - toString: function () { return '[[UNKNOWN]]'; } - }; - var UNDEFINED_EXPRESSION = { - included: true, - getLiteralValueAtPath: function () { return undefined; }, - getReturnExpressionWhenCalledAtPath: function () { return UNKNOWN_EXPRESSION; }, - hasEffectsWhenAccessedAtPath: function (path) { return path.length > 0; }, - hasEffectsWhenAssignedAtPath: function (path) { return path.length > 0; }, - hasEffectsWhenCalledAtPath: function () { return true; }, - include: function () { }, - deoptimizePath: function () { }, - toString: function () { return 'undefined'; } - }; - var returnsUnknown = { - value: { - returns: null, - returnsPrimitive: UNKNOWN_EXPRESSION, - callsArgs: null, - mutatesSelf: false - } - }; - var mutatesSelfReturnsUnknown = { - value: { returns: null, returnsPrimitive: UNKNOWN_EXPRESSION, callsArgs: null, mutatesSelf: true } - }; - var callsArgReturnsUnknown = { - value: { returns: null, returnsPrimitive: UNKNOWN_EXPRESSION, callsArgs: [0], mutatesSelf: false } - }; - var UnknownArrayExpression = /** @class */ (function () { - function UnknownArrayExpression() { - this.included = false; - } - UnknownArrayExpression.prototype.getLiteralValueAtPath = function () { - return UNKNOWN_VALUE; - }; - UnknownArrayExpression.prototype.getReturnExpressionWhenCalledAtPath = function (path) { - if (path.length === 1) { - return getMemberReturnExpressionWhenCalled(arrayMembers, path[0]); - } - return UNKNOWN_EXPRESSION; - }; - UnknownArrayExpression.prototype.hasEffectsWhenAccessedAtPath = function (path) { - return path.length > 1; - }; - UnknownArrayExpression.prototype.hasEffectsWhenAssignedAtPath = function (path) { - return path.length > 1; - }; - UnknownArrayExpression.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - if (path.length === 1) { - return hasMemberEffectWhenCalled(arrayMembers, path[0], this.included, callOptions, options); - } - return true; - }; - UnknownArrayExpression.prototype.include = function () { - this.included = true; - }; - UnknownArrayExpression.prototype.deoptimizePath = function () { }; - UnknownArrayExpression.prototype.toString = function () { - return '[[UNKNOWN ARRAY]]'; - }; - return UnknownArrayExpression; - }()); - var returnsArray = { - value: { - returns: UnknownArrayExpression, - returnsPrimitive: null, - callsArgs: null, - mutatesSelf: false - } - }; - var mutatesSelfReturnsArray = { - value: { - returns: UnknownArrayExpression, - returnsPrimitive: null, - callsArgs: null, - mutatesSelf: true - } - }; - var callsArgReturnsArray = { - value: { - returns: UnknownArrayExpression, - returnsPrimitive: null, - callsArgs: [0], - mutatesSelf: false - } - }; - var callsArgMutatesSelfReturnsArray = { - value: { - returns: UnknownArrayExpression, - returnsPrimitive: null, - callsArgs: [0], - mutatesSelf: true - } - }; - var UNKNOWN_LITERAL_BOOLEAN = { - included: true, - getLiteralValueAtPath: function () { return UNKNOWN_VALUE; }, - getReturnExpressionWhenCalledAtPath: function (path) { - if (path.length === 1) { - return getMemberReturnExpressionWhenCalled(literalBooleanMembers, path[0]); - } - return UNKNOWN_EXPRESSION; - }, - hasEffectsWhenAccessedAtPath: function (path) { return path.length > 1; }, - hasEffectsWhenAssignedAtPath: function (path) { return path.length > 0; }, - hasEffectsWhenCalledAtPath: function (path) { - if (path.length === 1) { - var subPath = path[0]; - return typeof subPath !== 'string' || !literalBooleanMembers[subPath]; - } - return true; - }, - include: function () { }, - deoptimizePath: function () { }, - toString: function () { return '[[UNKNOWN BOOLEAN]]'; } - }; - var returnsBoolean = { - value: { - returns: null, - returnsPrimitive: UNKNOWN_LITERAL_BOOLEAN, - callsArgs: null, - mutatesSelf: false - } - }; - var callsArgReturnsBoolean = { - value: { - returns: null, - returnsPrimitive: UNKNOWN_LITERAL_BOOLEAN, - callsArgs: [0], - mutatesSelf: false - } - }; - var UNKNOWN_LITERAL_NUMBER = { - included: true, - getLiteralValueAtPath: function () { return UNKNOWN_VALUE; }, - getReturnExpressionWhenCalledAtPath: function (path) { - if (path.length === 1) { - return getMemberReturnExpressionWhenCalled(literalNumberMembers, path[0]); - } - return UNKNOWN_EXPRESSION; - }, - hasEffectsWhenAccessedAtPath: function (path) { return path.length > 1; }, - hasEffectsWhenAssignedAtPath: function (path) { return path.length > 0; }, - hasEffectsWhenCalledAtPath: function (path) { - if (path.length === 1) { - var subPath = path[0]; - return typeof subPath !== 'string' || !literalNumberMembers[subPath]; - } - return true; - }, - include: function () { }, - deoptimizePath: function () { }, - toString: function () { return '[[UNKNOWN NUMBER]]'; } - }; - var returnsNumber = { - value: { - returns: null, - returnsPrimitive: UNKNOWN_LITERAL_NUMBER, - callsArgs: null, - mutatesSelf: false - } - }; - var mutatesSelfReturnsNumber = { - value: { - returns: null, - returnsPrimitive: UNKNOWN_LITERAL_NUMBER, - callsArgs: null, - mutatesSelf: true - } - }; - var callsArgReturnsNumber = { - value: { - returns: null, - returnsPrimitive: UNKNOWN_LITERAL_NUMBER, - callsArgs: [0], - mutatesSelf: false - } - }; - var UNKNOWN_LITERAL_STRING = { - included: true, - getLiteralValueAtPath: function () { return UNKNOWN_VALUE; }, - getReturnExpressionWhenCalledAtPath: function (path) { - if (path.length === 1) { - return getMemberReturnExpressionWhenCalled(literalStringMembers, path[0]); - } - return UNKNOWN_EXPRESSION; - }, - hasEffectsWhenAccessedAtPath: function (path) { return path.length > 1; }, - hasEffectsWhenAssignedAtPath: function (path) { return path.length > 0; }, - hasEffectsWhenCalledAtPath: function (path) { - if (path.length === 1) { - var subPath = path[0]; - return typeof subPath !== 'string' || !literalStringMembers[subPath]; - } - return true; - }, - include: function () { }, - deoptimizePath: function () { }, - toString: function () { return '[[UNKNOWN STRING]]'; } - }; - var returnsString = { - value: { - returns: null, - returnsPrimitive: UNKNOWN_LITERAL_STRING, - callsArgs: null, - mutatesSelf: false - } - }; - var UnknownObjectExpression = /** @class */ (function () { - function UnknownObjectExpression() { - this.included = false; - } - UnknownObjectExpression.prototype.getLiteralValueAtPath = function () { - return UNKNOWN_VALUE; - }; - UnknownObjectExpression.prototype.getReturnExpressionWhenCalledAtPath = function (path) { - if (path.length === 1) { - return getMemberReturnExpressionWhenCalled(objectMembers, path[0]); - } - return UNKNOWN_EXPRESSION; - }; - UnknownObjectExpression.prototype.hasEffectsWhenAccessedAtPath = function (path) { - return path.length > 1; - }; - UnknownObjectExpression.prototype.hasEffectsWhenAssignedAtPath = function (path) { - return path.length > 1; - }; - UnknownObjectExpression.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - if (path.length === 1) { - return hasMemberEffectWhenCalled(objectMembers, path[0], this.included, callOptions, options); - } - return true; - }; - UnknownObjectExpression.prototype.include = function () { - this.included = true; - }; - UnknownObjectExpression.prototype.deoptimizePath = function () { }; - UnknownObjectExpression.prototype.toString = function () { - return '[[UNKNOWN OBJECT]]'; - }; - return UnknownObjectExpression; - }()); - var objectMembers = assembleMemberDescriptions({ - hasOwnProperty: returnsBoolean, - isPrototypeOf: returnsBoolean, - propertyIsEnumerable: returnsBoolean, - toLocaleString: returnsString, - toString: returnsString, - valueOf: returnsUnknown - }); - var arrayMembers = assembleMemberDescriptions({ - concat: returnsArray, - copyWithin: mutatesSelfReturnsArray, - every: callsArgReturnsBoolean, - fill: mutatesSelfReturnsArray, - filter: callsArgReturnsArray, - find: callsArgReturnsUnknown, - findIndex: callsArgReturnsNumber, - forEach: callsArgReturnsUnknown, - includes: returnsBoolean, - indexOf: returnsNumber, - join: returnsString, - lastIndexOf: returnsNumber, - map: callsArgReturnsArray, - pop: mutatesSelfReturnsUnknown, - push: mutatesSelfReturnsNumber, - reduce: callsArgReturnsUnknown, - reduceRight: callsArgReturnsUnknown, - reverse: mutatesSelfReturnsArray, - shift: mutatesSelfReturnsUnknown, - slice: returnsArray, - some: callsArgReturnsBoolean, - sort: callsArgMutatesSelfReturnsArray, - splice: mutatesSelfReturnsArray, - unshift: mutatesSelfReturnsNumber - }, objectMembers); - var literalBooleanMembers = assembleMemberDescriptions({ - valueOf: returnsBoolean - }, objectMembers); - var literalNumberMembers = assembleMemberDescriptions({ - toExponential: returnsString, - toFixed: returnsString, - toLocaleString: returnsString, - toPrecision: returnsString, - valueOf: returnsNumber - }, objectMembers); - var literalStringMembers = assembleMemberDescriptions({ - charAt: returnsString, - charCodeAt: returnsNumber, - codePointAt: returnsNumber, - concat: returnsString, - includes: returnsBoolean, - endsWith: returnsBoolean, - indexOf: returnsNumber, - lastIndexOf: returnsNumber, - localeCompare: returnsNumber, - match: returnsBoolean, - normalize: returnsString, - padEnd: returnsString, - padStart: returnsString, - repeat: returnsString, - replace: { - value: { - returns: null, - returnsPrimitive: UNKNOWN_LITERAL_STRING, - callsArgs: [1], - mutatesSelf: false - } - }, - search: returnsNumber, - slice: returnsString, - split: returnsArray, - startsWith: returnsBoolean, - substr: returnsString, - substring: returnsString, - toLocaleLowerCase: returnsString, - toLocaleUpperCase: returnsString, - toLowerCase: returnsString, - toUpperCase: returnsString, - trim: returnsString, - valueOf: returnsString - }, objectMembers); - function getLiteralMembersForValue(value) { - switch (typeof value) { - case 'boolean': - return literalBooleanMembers; - case 'number': - return literalNumberMembers; - case 'string': - return literalStringMembers; - default: - return Object.create(null); - } - } - function hasMemberEffectWhenCalled(members, memberName, parentIncluded, callOptions, options) { - if (typeof memberName !== 'string' || !members[memberName]) - return true; - if (members[memberName].mutatesSelf && parentIncluded) - return true; - if (!members[memberName].callsArgs) - return false; - for (var _i = 0, _a = members[memberName].callsArgs; _i < _a.length; _i++) { - var argIndex = _a[_i]; - if (callOptions.args[argIndex] && - callOptions.args[argIndex].hasEffectsWhenCalledAtPath(EMPTY_PATH, CallOptions.create({ - withNew: false, - args: [], - callIdentifier: {} // make sure the caller is unique to avoid this check being ignored - }), options.getHasEffectsWhenCalledOptions())) - return true; - } - return false; - } - function getMemberReturnExpressionWhenCalled(members, memberName) { - if (typeof memberName !== 'string' || !members[memberName]) - return UNKNOWN_EXPRESSION; - return members[memberName].returnsPrimitive !== null - ? members[memberName].returnsPrimitive - : new members[memberName].returns(); - } - - var Variable = /** @class */ (function () { - function Variable(name) { - // Not initialised during construction - this.exportName = null; - this.safeExportName = null; - this.included = false; - this.isId = false; - this.reexported = false; - this.isReassigned = false; - this.name = name; - this.safeName = null; - } - /** - * Binds identifiers that reference this variable to this variable. - * Necessary to be able to change variable names. - */ - Variable.prototype.addReference = function (_identifier) { }; - Variable.prototype.getName = function (reset) { - if (reset && - this.safeName && - this.safeName !== this.name && - this.safeName[this.name.length] === '$' && - this.safeName[this.name.length + 1] === '$') { - this.safeName = undefined; - return this.name; - } - return this.safeName || this.name; - }; - Variable.prototype.getLiteralValueAtPath = function (_path, _recursionTracker, _origin) { - return UNKNOWN_VALUE; - }; - Variable.prototype.getReturnExpressionWhenCalledAtPath = function (_path, _recursionTracker, _origin) { - return UNKNOWN_EXPRESSION; - }; - Variable.prototype.hasEffectsWhenAccessedAtPath = function (path, _options) { - return path.length > 0; - }; - Variable.prototype.hasEffectsWhenAssignedAtPath = function (_path, _options) { - return true; - }; - Variable.prototype.hasEffectsWhenCalledAtPath = function (_path, _callOptions, _options) { - return true; - }; - /** - * Marks this variable as being part of the bundle, which is usually the case when one of - * its identifiers becomes part of the bundle. Returns true if it has not been included - * previously. - * Once a variable is included, it should take care all its declarations are included. - */ - Variable.prototype.include = function () { - this.included = true; - }; - Variable.prototype.deoptimizePath = function (_path) { }; - Variable.prototype.setSafeName = function (name) { - this.safeName = name; - }; - Variable.prototype.toString = function () { - return this.name; - }; - return Variable; - }()); - - // To avoid infinite recursions - var MAX_PATH_DEPTH = 7; - var LocalVariable = /** @class */ (function (_super) { - __extends(LocalVariable, _super); - function LocalVariable(name, declarator, init, deoptimizationTracker) { - var _this = _super.call(this, name) || this; - _this.additionalInitializers = null; - _this.expressionsToBeDeoptimized = []; - _this.declarations = declarator ? [declarator] : []; - _this.init = init; - _this.deoptimizationTracker = deoptimizationTracker; - return _this; - } - LocalVariable.prototype.addDeclaration = function (identifier, init) { - this.declarations.push(identifier); - if (this.additionalInitializers === null) { - this.additionalInitializers = this.init === null ? [] : [this.init]; - this.init = UNKNOWN_EXPRESSION; - this.isReassigned = true; - } - if (init !== null) { - this.additionalInitializers.push(init); - } - }; - LocalVariable.prototype.consolidateInitializers = function () { - if (this.additionalInitializers !== null) { - for (var _i = 0, _a = this.additionalInitializers; _i < _a.length; _i++) { - var initializer = _a[_i]; - initializer.deoptimizePath(UNKNOWN_PATH); - } - this.additionalInitializers = null; - } - }; - LocalVariable.prototype.getLiteralValueAtPath = function (path, recursionTracker, origin) { - if (this.isReassigned || - !this.init || - path.length > MAX_PATH_DEPTH || - recursionTracker.isTracked(this.init, path)) { - return UNKNOWN_VALUE; - } - this.expressionsToBeDeoptimized.push(origin); - return this.init.getLiteralValueAtPath(path, recursionTracker.track(this.init, path), origin); - }; - LocalVariable.prototype.getReturnExpressionWhenCalledAtPath = function (path, recursionTracker, origin) { - if (this.isReassigned || - !this.init || - path.length > MAX_PATH_DEPTH || - recursionTracker.isTracked(this.init, path)) { - return UNKNOWN_EXPRESSION; - } - this.expressionsToBeDeoptimized.push(origin); - return this.init.getReturnExpressionWhenCalledAtPath(path, recursionTracker.track(this.init, path), origin); - }; - LocalVariable.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - if (path.length === 0) - return false; - return (this.isReassigned || - path.length > MAX_PATH_DEPTH || - (this.init && - !options.hasNodeBeenAccessedAtPath(path, this.init) && - this.init.hasEffectsWhenAccessedAtPath(path, options.addAccessedNodeAtPath(path, this.init)))); - }; - LocalVariable.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - if (this.included || path.length > MAX_PATH_DEPTH) - return true; - if (path.length === 0) - return false; - return (this.isReassigned || - (this.init && - !options.hasNodeBeenAssignedAtPath(path, this.init) && - this.init.hasEffectsWhenAssignedAtPath(path, options.addAssignedNodeAtPath(path, this.init)))); - }; - LocalVariable.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - if (path.length > MAX_PATH_DEPTH) - return true; - return (this.isReassigned || - (this.init && - !options.hasNodeBeenCalledAtPathWithOptions(path, this.init, callOptions) && - this.init.hasEffectsWhenCalledAtPath(path, callOptions, options.addCalledNodeAtPathWithOptions(path, this.init, callOptions)))); - }; - LocalVariable.prototype.include = function () { - if (!this.included) { - this.included = true; - for (var _i = 0, _a = this.declarations; _i < _a.length; _i++) { - var declaration = _a[_i]; - // If node is a default export, it can save a tree-shaking run to include the full declaration now - if (!declaration.included) - declaration.include(); - var node = declaration.parent; - while (!node.included) { - // We do not want to properly include parents in case they are part of a dead branch - // in which case .include() might pull in more dead code - node.included = true; - if (node.type === Program) - break; - node = node.parent; - } - } - } - }; - LocalVariable.prototype.deoptimizePath = function (path) { - if (path.length > MAX_PATH_DEPTH) - return; - if (!(this.isReassigned || this.deoptimizationTracker.track(this, path))) { - if (path.length === 0) { - if (!this.isReassigned) { - this.isReassigned = true; - for (var _i = 0, _a = this.expressionsToBeDeoptimized; _i < _a.length; _i++) { - var expression = _a[_i]; - expression.deoptimizeCache(); - } - if (this.init) { - this.init.deoptimizePath(UNKNOWN_PATH); - } - } - } - else if (this.init) { - this.init.deoptimizePath(path); - } - } - }; - return LocalVariable; - }(Variable)); - LocalVariable.prototype.isLocal = true; - - function isExportDefaultVariable(variable) { - return variable.isDefault; - } - var ExportDefaultVariable = /** @class */ (function (_super) { - __extends(ExportDefaultVariable, _super); - function ExportDefaultVariable(name, exportDefaultDeclaration, deoptimizationTracker) { - var _this = _super.call(this, name, exportDefaultDeclaration, exportDefaultDeclaration.declaration, deoptimizationTracker) || this; - // Not initialised during construction - _this.original = null; - _this.hasId = !!exportDefaultDeclaration.declaration - .id; - return _this; - } - ExportDefaultVariable.prototype.addReference = function (identifier) { - if (!this.hasId) { - this.name = identifier.name; - if (this.original !== null) { - this.original.addReference(identifier); - } - } - }; - ExportDefaultVariable.prototype.getName = function (reset) { - if (!reset && this.safeName) - return this.safeName; - if (this.original !== null && !this.original.isReassigned) - return this.original.getName(); - return this.name; - }; - ExportDefaultVariable.prototype.referencesOriginal = function () { - return this.original && !this.original.isReassigned; - }; - ExportDefaultVariable.prototype.getOriginalVariableName = function () { - return this.original && this.original.getName(); - }; - ExportDefaultVariable.prototype.setOriginalVariable = function (original) { - this.original = original; - }; - return ExportDefaultVariable; - }(LocalVariable)); - ExportDefaultVariable.prototype.isDefault = true; - - var pureFunctions = {}; - var arrayTypes = 'Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split(' '); - var simdTypes = 'Int8x16 Int16x8 Int32x4 Float32x4 Float64x2'.split(' '); - var simdMethods = 'abs add and bool check div equal extractLane fromFloat32x4 fromFloat32x4Bits fromFloat64x2 fromFloat64x2Bits fromInt16x8Bits fromInt32x4 fromInt32x4Bits fromInt8x16Bits greaterThan greaterThanOrEqual lessThan lessThanOrEqual load max maxNum min minNum mul neg not notEqual or reciprocalApproximation reciprocalSqrtApproximation replaceLane select selectBits shiftLeftByScalar shiftRightArithmeticByScalar shiftRightLogicalByScalar shuffle splat sqrt store sub swizzle xor'.split(' '); - var allSimdMethods = []; - simdTypes.forEach(function (t) { - simdMethods.forEach(function (m) { - allSimdMethods.push("SIMD." + t + "." + m); - }); - }); - [ - 'Array.isArray', - 'Error', - 'EvalError', - 'InternalError', - 'RangeError', - 'ReferenceError', - 'SyntaxError', - 'TypeError', - 'URIError', - 'isFinite', - 'isNaN', - 'parseFloat', - 'parseInt', - 'decodeURI', - 'decodeURIComponent', - 'encodeURI', - 'encodeURIComponent', - 'escape', - 'unescape', - 'Object', - 'Object.create', - 'Object.getNotifier', - 'Object.getOwn', - 'Object.getOwnPropertyDescriptor', - 'Object.getOwnPropertyNames', - 'Object.getOwnPropertySymbols', - 'Object.getPrototypeOf', - 'Object.is', - 'Object.isExtensible', - 'Object.isFrozen', - 'Object.isSealed', - 'Object.keys', - 'Boolean', - 'Number', - 'Number.isFinite', - 'Number.isInteger', - 'Number.isNaN', - 'Number.isSafeInteger', - 'Number.parseFloat', - 'Number.parseInt', - 'Symbol', - 'Symbol.for', - 'Symbol.keyFor', - 'Math.abs', - 'Math.acos', - 'Math.acosh', - 'Math.asin', - 'Math.asinh', - 'Math.atan', - 'Math.atan2', - 'Math.atanh', - 'Math.cbrt', - 'Math.ceil', - 'Math.clz32', - 'Math.cos', - 'Math.cosh', - 'Math.exp', - 'Math.expm1', - 'Math.floor', - 'Math.fround', - 'Math.hypot', - 'Math.imul', - 'Math.log', - 'Math.log10', - 'Math.log1p', - 'Math.log2', - 'Math.max', - 'Math.min', - 'Math.pow', - 'Math.random', - 'Math.round', - 'Math.sign', - 'Math.sin', - 'Math.sinh', - 'Math.sqrt', - 'Math.tan', - 'Math.tanh', - 'Math.trunc', - 'Date', - 'Date.UTC', - 'Date.now', - 'Date.parse', - 'String', - 'String.fromCharCode', - 'String.fromCodePoint', - 'String.raw', - 'RegExp', - 'Map', - 'Set', - 'WeakMap', - 'WeakSet', - 'ArrayBuffer', - 'ArrayBuffer.isView', - 'DataView', - 'Promise.all', - 'Promise.race', - 'Promise.resolve', - 'Intl.Collator', - 'Intl.Collator.supportedLocalesOf', - 'Intl.DateTimeFormat', - 'Intl.DateTimeFormat.supportedLocalesOf', - 'Intl.NumberFormat', - 'Intl.NumberFormat.supportedLocalesOf' - // TODO properties of e.g. window... - ] - .concat(arrayTypes, arrayTypes.map(function (t) { return t + ".from"; }), arrayTypes.map(function (t) { return t + ".of"; }), simdTypes.map(function (t) { return "SIMD." + t; }), allSimdMethods) - .forEach(function (name) { return (pureFunctions[name] = true); }); - - var GlobalVariable = /** @class */ (function (_super) { - __extends(GlobalVariable, _super); - function GlobalVariable() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.included = true; - return _this; - } - GlobalVariable.prototype.hasEffectsWhenAccessedAtPath = function (path) { - // path.length == 0 can also have an effect but we postpone this for now - return (path.length > 0 && - !this.isPureFunctionMember(path) && - !(this.name === 'Reflect' && path.length === 1)); - }; - GlobalVariable.prototype.hasEffectsWhenCalledAtPath = function (path) { - return !pureFunctions[[this.name].concat(path).join('.')]; - }; - GlobalVariable.prototype.isPureFunctionMember = function (path) { - return (pureFunctions[[this.name].concat(path).join('.')] || - (path.length >= 1 && pureFunctions[[this.name].concat(path.slice(0, -1)).join('.')]) || - (path.length >= 2 && - pureFunctions[[this.name].concat(path.slice(0, -2)).join('.')] && - path[path.length - 2] === 'prototype')); - }; - return GlobalVariable; - }(Variable)); - - var ExternalVariable = /** @class */ (function (_super) { - __extends(ExternalVariable, _super); - function ExternalVariable(module, name) { - var _this = _super.call(this, name) || this; - _this.module = module; - _this.isNamespace = name === '*'; - _this.referenced = false; - return _this; - } - ExternalVariable.prototype.addReference = function (identifier) { - this.referenced = true; - if (this.name === 'default' || this.name === '*') { - this.module.suggestName(identifier.name); - } - }; - ExternalVariable.prototype.include = function () { - if (!this.included) { - this.included = true; - this.module.used = true; - } - }; - return ExternalVariable; - }(Variable)); - ExternalVariable.prototype.isExternal = true; - - var reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'.split(' '); - var builtins = 'Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl'.split(' '); - var blacklisted = Object.create(null); - reservedWords.concat(builtins).forEach(function (word) { return (blacklisted[word] = true); }); - var illegalCharacters = /[^$_a-zA-Z0-9]/g; - var startsWithDigit = function (str) { return /\d/.test(str[0]); }; - function isLegal(str) { - if (startsWithDigit(str) || blacklisted[str]) { - return false; - } - return !illegalCharacters.test(str); - } - function makeLegal(str) { - str = str.replace(/-(\w)/g, function (_, letter) { return letter.toUpperCase(); }).replace(illegalCharacters, '_'); - if (startsWithDigit(str) || blacklisted[str]) - str = "_" + str; - return str; - } - - var absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/; - var relativePath = /^\.?\.\//; - function isAbsolute(path) { - return absolutePath.test(path); - } - function isRelative(path) { - return relativePath.test(path); - } - function normalize(path) { - return path.replace(/\\/g, '/'); - } - function basename(path) { - return path.split(/(\/|\\)/).pop(); - } - function dirname(path) { - var match = /(\/|\\)[^/\\]*$/.exec(path); - if (!match) - return '.'; - var dir = path.slice(0, -match[0].length); - // If `dir` is the empty string, we're at root. - return dir ? dir : '/'; - } - function extname(path) { - var match = /\.[^.]+$/.exec(basename(path)); - if (!match) - return ''; - return match[0]; - } - function relative(from, to) { - var fromParts = from.split(/[/\\]/).filter(Boolean); - var toParts = to.split(/[/\\]/).filter(Boolean); - while (fromParts[0] && toParts[0] && fromParts[0] === toParts[0]) { - fromParts.shift(); - toParts.shift(); - } - while (toParts[0] === '.' || toParts[0] === '..') { - var toPart = toParts.shift(); - if (toPart === '..') { - fromParts.pop(); - } - } - while (fromParts.pop()) { - toParts.unshift('..'); - } - return toParts.join('/'); - } - function resolve() { - var paths = []; - for (var _i = 0; _i < arguments.length; _i++) { - paths[_i] = arguments[_i]; - } - var resolvedParts = paths.shift().split(/[/\\]/); - paths.forEach(function (path) { - if (isAbsolute(path)) { - resolvedParts = path.split(/[/\\]/); - } - else { - var parts = path.split(/[/\\]/); - while (parts[0] === '.' || parts[0] === '..') { - var part = parts.shift(); - if (part === '..') { - resolvedParts.pop(); - } - } - resolvedParts.push.apply(resolvedParts, parts); - } - }); - return resolvedParts.join('/'); // TODO windows... - } - - var ExternalModule = /** @class */ (function () { - function ExternalModule(_a) { - var graph = _a.graph, id = _a.id; - this.exportsNames = false; - this.exportsNamespace = false; - this.renderPath = undefined; - this.renormalizeRenderPath = false; - this.isExternal = true; - this.isEntryPoint = false; - this.mostCommonSuggestion = 0; - this.reexported = false; - this.used = false; - this.execIndex = undefined; - this.graph = graph; - this.id = id; - var parts = id.split(/[\\/]/); - this.name = makeLegal(parts.pop()); - this.nameSuggestions = Object.create(null); - this.declarations = Object.create(null); - this.exportedVariables = new Map(); - } - ExternalModule.prototype.setRenderPath = function (options, inputBase) { - if (options.paths) - this.renderPath = - typeof options.paths === 'function' ? options.paths(this.id) : options.paths[this.id]; - if (!this.renderPath) { - if (!isAbsolute(this.id)) { - this.renderPath = this.id; - } - else { - this.renderPath = normalize(relative(inputBase, this.id)); - this.renormalizeRenderPath = true; - } - } - return this.renderPath; - }; - ExternalModule.prototype.suggestName = function (name) { - if (!this.nameSuggestions[name]) - this.nameSuggestions[name] = 0; - this.nameSuggestions[name] += 1; - if (this.nameSuggestions[name] > this.mostCommonSuggestion) { - this.mostCommonSuggestion = this.nameSuggestions[name]; - this.name = name; - } - }; - ExternalModule.prototype.warnUnusedImports = function () { - var _this = this; - var unused = Object.keys(this.declarations).filter(function (name) { - if (name === '*') - return false; - var declaration = _this.declarations[name]; - return !declaration.included && !_this.reexported && !declaration.referenced; - }); - if (unused.length === 0) - return; - var names = unused.length === 1 - ? "'" + unused[0] + "' is" - : unused - .slice(0, -1) - .map(function (name) { return "'" + name + "'"; }) - .join(', ') + " and '" + unused.slice(-1) + "' are"; - this.graph.warn({ - code: 'UNUSED_EXTERNAL_IMPORT', - source: this.id, - names: unused, - message: names + " imported from external module '" + this.id + "' but never used" - }); - }; - ExternalModule.prototype.traceExport = function (name, _isExportAllSearch) { - if (name !== 'default' && name !== '*') - this.exportsNames = true; - if (name === '*') - this.exportsNamespace = true; - var declaration = this.declarations[name]; - if (declaration) - return declaration; - this.declarations[name] = declaration = new ExternalVariable(this, name); - this.exportedVariables.set(declaration, name); - return declaration; - }; - return ExternalModule; - }()); - - var esModuleExport = "Object.defineProperty(exports, '__esModule', { value: true });"; - var compactEsModuleExport = "Object.defineProperty(exports,'__esModule',{value:true});"; - - function getExportBlock(exports, dependencies, namedExportsMode, interop, compact, mechanism) { - if (mechanism === void 0) { mechanism = 'return '; } - var _ = compact ? '' : ' '; - if (!namedExportsMode) { - var local_1; - exports.some(function (expt) { - if (expt.exported === 'default') { - local_1 = expt.local; - return true; - } - return false; - }); - // search for reexported default otherwise - if (!local_1) { - dependencies.some(function (dep) { - if (!dep.reexports) - return false; - return dep.reexports.some(function (expt) { - if (expt.reexported === 'default') { - local_1 = dep.namedExportsMode ? dep.name + "." + expt.imported : dep.name; - return true; - } - return false; - }); - }); - } - return "" + mechanism + local_1 + ";"; - } - var exportBlock = ''; - // star exports must always output first for precedence - dependencies.forEach(function (_a) { - var name = _a.name, reexports = _a.reexports; - if (reexports && namedExportsMode) { - reexports.forEach(function (specifier) { - if (specifier.reexported === '*') { - if (!compact && exportBlock) - exportBlock += '\n'; - exportBlock += "Object.keys(" + name + ").forEach(function" + _ + "(key)" + _ + "{" + _ + "exports[key]" + _ + "=" + _ + name + "[key];" + _ + "});"; - } - }); - } - }); - dependencies.forEach(function (_a) { - var name = _a.name, imports = _a.imports, reexports = _a.reexports, isChunk = _a.isChunk; - if (reexports && namedExportsMode) { - reexports.forEach(function (specifier) { - if (specifier.imported === 'default' && !isChunk) { - var exportsNamesOrNamespace = (imports && - imports.some(function (specifier) { return specifier.imported === '*' || specifier.imported !== 'default'; })) || - (reexports && - reexports.some(function (specifier) { return specifier.imported !== 'default' && specifier.imported !== '*'; })); - if (exportBlock && !compact) - exportBlock += '\n'; - if (exportsNamesOrNamespace) - exportBlock += "exports." + specifier.reexported + _ + "=" + _ + name + (interop !== false ? '__default' : '.default') + ";"; - else - exportBlock += "exports." + specifier.reexported + _ + "=" + _ + name + ";"; - } - else if (specifier.imported !== '*') { - if (exportBlock && !compact) - exportBlock += '\n'; - exportBlock += "exports." + specifier.reexported + _ + "=" + _ + name + "." + specifier.imported + ";"; - } - else if (specifier.reexported !== '*') { - if (exportBlock && !compact) - exportBlock += '\n'; - exportBlock += "exports." + specifier.reexported + _ + "=" + _ + name + ";"; - } - }); - } - }); - exports.forEach(function (expt) { - var lhs = "exports." + expt.exported; - var rhs = expt.local; - if (lhs === rhs) { - return; - } - if (exportBlock && !compact) - exportBlock += '\n'; - exportBlock += "" + lhs + _ + "=" + _ + rhs + ";"; - }); - return exportBlock; - } - - function getInteropBlock(dependencies, options, varOrConst) { - return dependencies - .map(function (_a) { - var name = _a.name, exportsNames = _a.exportsNames, exportsDefault = _a.exportsDefault, namedExportsMode = _a.namedExportsMode; - if (!namedExportsMode) - return; - if (!exportsDefault || options.interop === false) - return null; - if (exportsNames) { - if (options.compact) - return varOrConst + " " + name + "__default='default'in " + name + "?" + name + "['default']:" + name + ";"; - return varOrConst + " " + name + "__default = 'default' in " + name + " ? " + name + "['default'] : " + name + ";"; - } - if (options.compact) - return name + "=" + name + "&&" + name + ".hasOwnProperty('default')?" + name + "['default']:" + name + ";"; - return name + " = " + name + " && " + name + ".hasOwnProperty('default') ? " + name + "['default'] : " + name + ";"; - }) - .filter(Boolean) - .join(options.compact ? '' : '\n'); - } - - var builtins$1 = { - process: true, - events: true, - stream: true, - util: true, - path: true, - buffer: true, - querystring: true, - url: true, - string_decoder: true, - punycode: true, - http: true, - https: true, - os: true, - assert: true, - constants: true, - timers: true, - console: true, - vm: true, - zlib: true, - tty: true, - domain: true - }; - // Creating a browser chunk that depends on Node.js built-in modules ('util'). You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins - function warnOnBuiltins(graph, dependencies) { - var externalBuiltins = dependencies.map(function (_a) { - var id = _a.id; - return id; - }).filter(function (id) { return id in builtins$1; }); - if (!externalBuiltins.length) - return; - var detail = externalBuiltins.length === 1 - ? "module ('" + externalBuiltins[0] + "')" - : "modules (" + externalBuiltins - .slice(0, -1) - .map(function (name) { return "'" + name + "'"; }) - .join(', ') + " and '" + externalBuiltins.slice(-1) + "')"; - graph.warn({ - code: 'MISSING_NODE_BUILTINS', - modules: externalBuiltins, - message: "Creating a browser bundle that depends on Node.js built-in " + detail + ". You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins" - }); - } - - function amd(magicString, _a, options) { - var graph = _a.graph, namedExportsMode = _a.namedExportsMode, hasExports = _a.hasExports, indentString = _a.indentString, intro = _a.intro, outro = _a.outro, dynamicImport = _a.dynamicImport, needsAmdModule = _a.needsAmdModule, dependencies = _a.dependencies, exports = _a.exports, isEntryModuleFacade = _a.isEntryModuleFacade; - warnOnBuiltins(graph, dependencies); - var deps = dependencies.map(function (m) { return "'" + m.id + "'"; }); - var args = dependencies.map(function (m) { return m.name; }); - var n = options.compact ? '' : '\n'; - var _ = options.compact ? '' : ' '; - if (namedExportsMode && hasExports) { - args.unshift("exports"); - deps.unshift("'exports'"); - } - if (dynamicImport) { - args.unshift('require'); - deps.unshift("'require'"); - } - if (needsAmdModule) { - args.unshift('module'); - deps.unshift("'module'"); - } - var amdOptions = options.amd || {}; - var params = (amdOptions.id ? "'" + amdOptions.id + "'," + _ : "") + - (deps.length ? "[" + deps.join("," + _) + "]," + _ : ""); - var useStrict = options.strict !== false ? _ + "'use strict';" : ""; - var define = amdOptions.define || 'define'; - var wrapperStart = define + "(" + params + "function" + _ + "(" + args.join("," + _) + ")" + _ + "{" + useStrict + n + n; - // var foo__default = 'default' in foo ? foo['default'] : foo; - var interopBlock = getInteropBlock(dependencies, options, graph.varOrConst); - if (interopBlock) - magicString.prepend(interopBlock + n + n); - if (intro) - magicString.prepend(intro); - var exportBlock = getExportBlock(exports, dependencies, namedExportsMode, options.interop, options.compact); - if (exportBlock) - magicString.append(n + n + exportBlock); - if (namedExportsMode && hasExports && isEntryModuleFacade && options.esModule) - magicString.append("" + n + n + (options.compact ? compactEsModuleExport : esModuleExport)); - if (outro) - magicString.append(outro); - return magicString - .indent(indentString) - .append(n + n + '});') - .prepend(wrapperStart); - } - - function cjs(magicString, _a, options) { - var graph = _a.graph, isEntryModuleFacade = _a.isEntryModuleFacade, namedExportsMode = _a.namedExportsMode, hasExports = _a.hasExports, intro = _a.intro, outro = _a.outro, dependencies = _a.dependencies, exports = _a.exports; - var n = options.compact ? '' : '\n'; - var _ = options.compact ? '' : ' '; - intro = - (options.strict === false ? intro : "'use strict';" + n + n + intro) + - (namedExportsMode && hasExports && isEntryModuleFacade && options.esModule - ? "" + (options.compact ? compactEsModuleExport : esModuleExport) + n + n - : ''); - var needsInterop = false; - var varOrConst = graph.varOrConst; - var interop = options.interop !== false; - var importBlock; - if (options.compact) { - var definingVariable_1 = false; - importBlock = ''; - dependencies.forEach(function (_a) { - var id = _a.id, namedExportsMode = _a.namedExportsMode, isChunk = _a.isChunk, name = _a.name, reexports = _a.reexports, imports = _a.imports, exportsNames = _a.exportsNames, exportsDefault = _a.exportsDefault; - if (!reexports && !imports) { - importBlock += definingVariable_1 ? ';' : ','; - definingVariable_1 = false; - importBlock += "require('" + id + "')"; - } - else { - importBlock += definingVariable_1 ? ',' : "" + (importBlock ? ';' : '') + varOrConst + " "; - definingVariable_1 = true; - if (!interop || isChunk || !exportsDefault || !namedExportsMode) { - importBlock += name + "=require('" + id + "')"; - } - else { - needsInterop = true; - if (exportsNames) - importBlock += name + "=require('" + id + "')," + name + "__default=_interopDefault(" + name + ")"; - else - importBlock += name + "=_interopDefault(require('" + id + "'))"; - } - } - }); - if (importBlock.length) - importBlock += ';'; - } - else { - importBlock = dependencies - .map(function (_a) { - var id = _a.id, namedExportsMode = _a.namedExportsMode, isChunk = _a.isChunk, name = _a.name, reexports = _a.reexports, imports = _a.imports, exportsNames = _a.exportsNames, exportsDefault = _a.exportsDefault; - if (!reexports && !imports) - return "require('" + id + "');"; - if (!interop || isChunk || !exportsDefault || !namedExportsMode) - return varOrConst + " " + name + " = require('" + id + "');"; - needsInterop = true; - if (exportsNames) - return (varOrConst + " " + name + " = require('" + id + "');" + - ("\n" + varOrConst + " " + name + "__default = _interopDefault(" + name + ");")); - return varOrConst + " " + name + " = _interopDefault(require('" + id + "'));"; - }) - .join('\n'); - } - if (needsInterop) { - if (options.compact) - intro += "function _interopDefault(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}"; - else - intro += "function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\n"; - } - if (importBlock) - intro += importBlock + n + n; - var exportBlock = getExportBlock(exports, dependencies, namedExportsMode, options.interop, options.compact, "module.exports" + _ + "=" + _); - magicString.prepend(intro); - if (exportBlock) - magicString.append(n + n + exportBlock); - if (outro) - magicString.append(outro); - return magicString; - } - - function esm(magicString, _a, options) { - var intro = _a.intro, outro = _a.outro, dependencies = _a.dependencies, exports = _a.exports; - var _ = options.compact ? '' : ' '; - var n = options.compact ? '' : '\n'; - var importBlock = dependencies - .map(function (_a) { - var id = _a.id, reexports = _a.reexports, imports = _a.imports, name = _a.name; - if (!reexports && !imports) { - return "import" + _ + "'" + id + "';"; - } - var output = ''; - if (imports) { - var defaultImport_1 = imports.find(function (specifier) { return specifier.imported === 'default'; }); - var starImport_1 = imports.find(function (specifier) { return specifier.imported === '*'; }); - if (starImport_1) { - output += "import" + _ + "*" + _ + "as " + starImport_1.local + " from" + _ + "'" + id + "';"; - if (imports.length > 1) - output += n; - } - if (defaultImport_1 && imports.length === 1) { - output += "import " + defaultImport_1.local + " from" + _ + "'" + id + "';"; - } - else if (!starImport_1 || imports.length > 1) { - output += "import " + (defaultImport_1 ? defaultImport_1.local + "," + _ : '') + "{" + _ + imports - .filter(function (specifier) { return specifier !== defaultImport_1 && specifier !== starImport_1; }) - .map(function (specifier) { - if (specifier.imported === specifier.local) { - return specifier.imported; - } - else { - return specifier.imported + " as " + specifier.local; - } - }) - .join("," + _) + _ + "}" + _ + "from" + _ + "'" + id + "';"; - } - } - if (reexports) { - if (imports) - output += n; - var starExport_1 = reexports.find(function (specifier) { return specifier.reexported === '*'; }); - var namespaceReexport_1 = reexports.find(function (specifier) { return specifier.imported === '*' && specifier.reexported !== '*'; }); - if (starExport_1) { - output += "export" + _ + "*" + _ + "from" + _ + "'" + id + "';"; - if (reexports.length === 1) { - return output; - } - output += n; - } - if (namespaceReexport_1) { - if (!imports || - !imports.some(function (specifier) { return specifier.imported === '*' && specifier.local === name; })) - output += "import" + _ + "*" + _ + "as " + name + " from" + _ + "'" + id + "';" + n; - output += "export" + _ + "{" + _ + (name === namespaceReexport_1.reexported - ? name - : name + " as " + namespaceReexport_1.reexported) + " };"; - if (reexports.length === (starExport_1 ? 2 : 1)) { - return output; - } - output += n; - } - output += "export" + _ + "{" + _ + reexports - .filter(function (specifier) { return specifier !== starExport_1 && specifier !== namespaceReexport_1; }) - .map(function (specifier) { - if (specifier.imported === specifier.reexported) { - return specifier.imported; - } - else { - return specifier.imported + " as " + specifier.reexported; - } - }) - .join("," + _) + _ + "}" + _ + "from" + _ + "'" + id + "';"; - } - return output; - }) - .join(n); - if (importBlock) - intro += importBlock + n + n; - if (intro) - magicString.prepend(intro); - var exportBlock = []; - var exportDeclaration = []; - exports.forEach(function (specifier) { - if (specifier.exported === 'default') { - exportBlock.push("export default " + specifier.local + ";"); - } - else { - exportDeclaration.push(specifier.exported === specifier.local - ? specifier.local - : specifier.local + " as " + specifier.exported); - } - }); - if (exportDeclaration.length) { - exportBlock.push("export" + _ + "{" + _ + exportDeclaration.join("," + _) + _ + "};"); - } - if (exportBlock.length) - magicString.append(n + n + exportBlock.join(n).trim()); - if (outro) - magicString.append(outro); - return magicString.trim(); - } - - function error(props) { - if (props instanceof Error) - throw props; - var err = new Error(props.message); - Object.keys(props).forEach(function (key) { - err[key] = props[key]; - }); - throw err; - } - - // Generate strings which dereference dotted properties, but use array notation `['prop-deref']` - // if the property name isn't trivial - var shouldUseDot = /^[a-zA-Z$_][a-zA-Z0-9$_]*$/; - function property(prop) { - return shouldUseDot.test(prop) ? "." + prop : "['" + prop + "']"; - } - function keypath(keypath) { - return keypath - .split('.') - .map(property) - .join(''); - } - - function setupNamespace(name, root, forAssignment, globals, compact) { - var parts = name.split('.'); - if (globals) { - parts[0] = (typeof globals === 'function' ? globals(parts[0]) : globals[parts[0]]) || parts[0]; - } - var _ = compact ? '' : ' '; - var last = parts.pop(); - var acc = root; - if (forAssignment) { - return parts - .map(function (part) { return ((acc += property(part)), "" + acc + _ + "=" + _ + acc + _ + "||" + _ + "{}"); }) - .concat("" + acc + property(last)) - .join("," + _); - } - else { - return (parts - .map(function (part) { return ((acc += property(part)), "" + acc + _ + "=" + _ + acc + _ + "||" + _ + "{}" + (compact ? '' : ';')); }) - .join(compact ? ',' : '\n') + (compact && parts.length ? ';' : '\n')); - } - } - - function trimEmptyImports(dependencies) { - var i = dependencies.length; - while (i--) { - var dependency = dependencies[i]; - if (dependency.exportsDefault || dependency.exportsNames) { - return dependencies.slice(0, i + 1); - } - } - return []; - } - - var thisProp = function (name) { return "this" + keypath(name); }; - function iife(magicString, _a, options) { - var graph = _a.graph, namedExportsMode = _a.namedExportsMode, hasExports = _a.hasExports, t = _a.indentString, intro = _a.intro, outro = _a.outro, dependencies = _a.dependencies, exports = _a.exports; - var _ = options.compact ? '' : ' '; - var n = options.compact ? '' : '\n'; - var extend = options.extend, name = options.name; - var isNamespaced = name && name.indexOf('.') !== -1; - var possibleVariableAssignment = !extend && !isNamespaced; - if (name && possibleVariableAssignment && !isLegal(name)) { - error({ - code: 'ILLEGAL_IDENTIFIER_AS_NAME', - message: "Given name (" + name + ") is not legal JS identifier. If you need this you can try --extend option" - }); - } - warnOnBuiltins(graph, dependencies); - var external = trimEmptyImports(dependencies); - var deps = external.map(function (dep) { return dep.globalName || 'null'; }); - var args = external.map(function (m) { return m.name; }); - if (hasExports && !name) { - error({ - code: 'INVALID_OPTION', - message: "You must supply output.name for IIFE bundles" - }); - } - if (extend) { - deps.unshift("(" + thisProp(name) + _ + "=" + _ + thisProp(name) + _ + "||" + _ + "{})"); - args.unshift('exports'); - } - else if (namedExportsMode && hasExports) { - deps.unshift('{}'); - args.unshift('exports'); - } - var useStrict = options.strict !== false ? t + "'use strict';" + n + n : ""; - var wrapperIntro = "(function" + _ + "(" + args + ")" + _ + "{" + n + useStrict; - if (hasExports && !extend) { - wrapperIntro = - (isNamespaced ? thisProp(name) : graph.varOrConst + " " + name) + (_ + "=" + _ + wrapperIntro); - } - if (isNamespaced) { - wrapperIntro = - setupNamespace(name, 'this', false, options.globals, options.compact) + wrapperIntro; - } - var wrapperOutro = "" + n + n + "}(" + deps + "));"; - if (!extend && namedExportsMode && hasExports) { - wrapperOutro = "" + n + n + t + "return exports;" + wrapperOutro; - } - // var foo__default = 'default' in foo ? foo['default'] : foo; - var interopBlock = getInteropBlock(dependencies, options, graph.varOrConst); - if (interopBlock) - magicString.prepend(interopBlock + n + n); - if (intro) - magicString.prepend(intro); - var exportBlock = getExportBlock(exports, dependencies, namedExportsMode, options.interop, options.compact); - if (exportBlock) - magicString.append(n + n + exportBlock); - if (outro) - magicString.append(outro); - return magicString - .indent(t) - .prepend(wrapperIntro) - .append(wrapperOutro); - } - - function getStarExcludes(_a) { - var dependencies = _a.dependencies, exports = _a.exports; - var starExcludes = new Set(exports.map(function (expt) { return expt.exported; })); - if (!starExcludes.has('default')) - starExcludes.add('default'); - // also include reexport names - dependencies.forEach(function (_a) { - var reexports = _a.reexports; - if (reexports) - reexports.forEach(function (reexport) { - if (reexport.imported !== '*' && !starExcludes.has(reexport.reexported)) - starExcludes.add(reexport.reexported); - }); - }); - return starExcludes; - } - function system(magicString, _a, options) { - var graph = _a.graph, t = _a.indentString, intro = _a.intro, outro = _a.outro, dependencies = _a.dependencies, exports = _a.exports, usesTopLevelAwait = _a.usesTopLevelAwait; - var n = options.compact ? '' : '\n'; - var _ = options.compact ? '' : ' '; - var dependencyIds = dependencies.map(function (m) { return "'" + m.id + "'"; }); - var importBindings = []; - var starExcludes; - var setters = []; - var varOrConst = graph.varOrConst; - dependencies.forEach(function (_a) { - var imports = _a.imports, reexports = _a.reexports; - var setter = []; - if (imports) { - imports.forEach(function (specifier) { - importBindings.push(specifier.local); - if (specifier.imported === '*') { - setter.push("" + specifier.local + _ + "=" + _ + "module;"); - } - else { - setter.push("" + specifier.local + _ + "=" + _ + "module." + specifier.imported + ";"); - } - }); - } - if (reexports) { - var createdSetter_1 = false; - // bulk-reexport form - if (reexports.length > 1 || - (reexports.length === 1 && - (reexports[0].reexported === '*' || reexports[0].imported === '*'))) { - // star reexports - reexports.forEach(function (specifier) { - if (specifier.reexported !== '*') - return; - // need own exports list for deduping in star export case - if (!starExcludes) { - starExcludes = getStarExcludes({ dependencies: dependencies, exports: exports }); - } - if (!createdSetter_1) { - setter.push(varOrConst + " _setter" + _ + "=" + _ + "{};"); - createdSetter_1 = true; - } - setter.push("for" + _ + "(var _$p" + _ + "in" + _ + "module)" + _ + "{"); - setter.push(t + "if" + _ + "(!_starExcludes[_$p])" + _ + "_setter[_$p]" + _ + "=" + _ + "module[_$p];"); - setter.push('}'); - }); - // star import reexport - reexports.forEach(function (specifier) { - if (specifier.imported !== '*' || specifier.reexported === '*') - return; - setter.push("exports('" + specifier.reexported + "'," + _ + "module);"); - }); - // reexports - reexports.forEach(function (specifier) { - if (specifier.reexported === '*' || specifier.imported === '*') - return; - if (!createdSetter_1) { - setter.push(varOrConst + " _setter" + _ + "=" + _ + "{};"); - createdSetter_1 = true; - } - setter.push("_setter." + specifier.reexported + _ + "=" + _ + "module." + specifier.imported + ";"); - }); - if (createdSetter_1) { - setter.push('exports(_setter);'); - } - } - else { - // single reexport - reexports.forEach(function (specifier) { - setter.push("exports('" + specifier.reexported + "'," + _ + "module." + specifier.imported + ");"); - }); - } - } - setters.push(setter.join("" + n + t + t + t)); - }); - // function declarations hoist - var hoistedExports = []; - var hoistedExportObjs = exports.filter(function (expt) { return expt.hoisted || expt.uninitialized; }); - if (hoistedExportObjs.length === 1) { - var expt = hoistedExportObjs[0]; - hoistedExports.push("exports('" + expt.exported + "'," + _ + (expt.uninitialized ? 'void 0' : expt.local) + ");"); - } - else if (hoistedExportObjs.length > 1) { - hoistedExports.push("exports({"); - for (var i = 0; i < hoistedExportObjs.length; i++) { - var expt = hoistedExportObjs[i]; - hoistedExports.push("" + t + expt.exported + ":" + _ + (expt.uninitialized ? 'void 0' : expt.local) + (i === hoistedExportObjs.length - 1 ? '' : ',')); - } - hoistedExports.push("});"); - } - var starExcludesSection = !starExcludes - ? '' - : "" + n + t + varOrConst + " _starExcludes" + _ + "=" + _ + "{" + _ + Array.from(starExcludes).join(":" + _ + "1," + _) + (starExcludes.size ? ":" + _ + "1" : '') + _ + "};"; - var importBindingsSection = importBindings.length - ? "" + n + t + "var " + importBindings.join("," + _) + ";" - : ''; - var registeredName = options.name ? "'" + options.name + "'," + _ : ''; - var wrapperStart = "System.register(" + registeredName + "[" + dependencyIds.join("," + _) + "]," + _ + "function" + _ + "(exports," + _ + "module)" + _ + "{" + n; - wrapperStart += t + "'use strict';" + starExcludesSection + importBindingsSection + n; - wrapperStart += t + "return" + _ + "{" + (setters.length - ? "" + n + t + t + "setters:" + _ + "[" + setters - .map(function (s) { - return s - ? "function" + _ + "(module)" + _ + "{" + n + t + t + t + s + n + t + t + "}" - : "function" + _ + "()" + _ + "{}"; - }) - .join("," + _) + "]," - : '') + n; - wrapperStart += "" + t + t + "execute:" + _ + (usesTopLevelAwait ? "async" + _ : '') + "function" + _ + "()" + _ + "{" + n + n; - if (hoistedExports.length) - wrapperStart += "" + t + t + t + hoistedExports.join("" + n + t + t + t) + n + n; - var wrapperEnd = "" + n + n + t + t + "}"; - wrapperEnd += "" + n + t + "}" + (options.compact ? '' : ';'); - wrapperEnd += n + "});"; - if (intro) - magicString.prepend(intro); - if (outro) - magicString.append(outro); - return magicString - .indent("" + t + t + t) - .append(wrapperEnd) - .prepend(wrapperStart); - } - - function globalProp(name) { - if (!name) - return 'null'; - return "global" + keypath(name); - } - function safeAccess(name, compact) { - var parts = name.split('.'); - var acc = 'global'; - return parts.map(function (part) { return ((acc += property(part)), acc); }).join(compact ? '&&' : " && "); - } - function umd(magicString, _a, options) { - var graph = _a.graph, namedExportsMode = _a.namedExportsMode, hasExports = _a.hasExports, t = _a.indentString, intro = _a.intro, outro = _a.outro, dependencies = _a.dependencies, exports = _a.exports; - var _ = options.compact ? '' : ' '; - var n = options.compact ? '' : '\n'; - var wrapperOutro = n + n + '})));'; - if (hasExports && !options.name) { - error({ - code: 'INVALID_OPTION', - message: 'You must supply output.name for UMD bundles' - }); - } - warnOnBuiltins(graph, dependencies); - var amdDeps = dependencies.map(function (m) { return "'" + m.id + "'"; }); - var cjsDeps = dependencies.map(function (m) { return "require('" + m.id + "')"; }); - var trimmed = trimEmptyImports(dependencies); - var globalDeps = trimmed.map(function (module) { return globalProp(module.globalName); }); - var args = trimmed.map(function (m) { return m.name; }); - if (namedExportsMode && hasExports) { - amdDeps.unshift("'exports'"); - cjsDeps.unshift("exports"); - globalDeps.unshift("(" + setupNamespace(options.name, 'global', true, options.globals, options.compact) + _ + "=" + _ + (options.extend ? "" + globalProp(options.name) + _ + "||" + _ : '') + "{})"); - args.unshift('exports'); - } - var amdOptions = options.amd || {}; - var amdParams = (amdOptions.id ? "'" + amdOptions.id + "'," + _ : "") + - (amdDeps.length ? "[" + amdDeps.join("," + _) + "]," + _ : ""); - var define = amdOptions.define || 'define'; - var cjsExport = !namedExportsMode && hasExports ? "module.exports" + _ + "=" + _ : ""; - var defaultExport = !namedExportsMode && hasExports - ? "" + setupNamespace(options.name, 'global', true, options.globals, options.compact) + _ + "=" + _ - : ''; - var useStrict = options.strict !== false ? _ + "'use strict';" + n : ""; - var globalExport; - if (options.noConflict === true) { - var factory = void 0; - if (!namedExportsMode && hasExports) { - factory = "var exports" + _ + "=" + _ + "factory(" + globalDeps + ");"; - } - else if (namedExportsMode) { - var module = globalDeps.shift(); - factory = "var exports" + _ + "=" + _ + module + ";" + n; - factory += "" + t + t + "factory(" + ['exports'].concat(globalDeps) + ");"; - } - globalExport = "(function()" + _ + "{" + n; - globalExport += "" + t + t + "var current" + _ + "=" + _ + safeAccess(options.name, options.compact) + ";" + n; - globalExport += "" + t + t + factory + n; - globalExport += "" + t + t + globalProp(options.name) + _ + "=" + _ + "exports;" + n; - globalExport += "" + t + t + "exports.noConflict" + _ + "=" + _ + "function()" + _ + "{" + _; - globalExport += "" + globalProp(options.name) + _ + "=" + _ + "current;" + _ + "return exports" + (options.compact ? '' : '; ') + "};" + n; - globalExport += t + "})()"; - } - else { - globalExport = "(" + defaultExport + "factory(" + globalDeps + "))"; - } - var wrapperIntro = "(function" + _ + "(global," + _ + "factory)" + _ + "{" + n; - wrapperIntro += t + "typeof exports" + _ + "===" + _ + "'object'" + _ + "&&" + _ + "typeof module" + _ + "!==" + _ + "'undefined'" + _ + "?"; - wrapperIntro += "" + _ + cjsExport + "factory(" + cjsDeps.join("," + _) + ")" + _ + ":" + n; - wrapperIntro += t + "typeof " + define + _ + "===" + _ + "'function'" + _ + "&&" + _ + define + ".amd" + _ + "?" + _ + define + "(" + amdParams + "factory)" + _ + ":" + n; - wrapperIntro += "" + t + globalExport + ";" + n; - wrapperIntro += "}(this," + _ + "(function" + _ + "(" + args + ")" + _ + "{" + useStrict + n; - // var foo__default = 'default' in foo ? foo['default'] : foo; - var interopBlock = getInteropBlock(dependencies, options, graph.varOrConst); - if (interopBlock) - magicString.prepend(interopBlock + n + n); - if (intro) - magicString.prepend(intro); - var exportBlock = getExportBlock(exports, dependencies, namedExportsMode, options.interop, options.compact); - if (exportBlock) - magicString.append(n + n + exportBlock); - if (namedExportsMode && hasExports && options.esModule) - magicString.append(n + n + (options.compact ? compactEsModuleExport : esModuleExport)); - if (outro) - magicString.append(outro); - return magicString - .trim() - .indent(t) - .append(wrapperOutro) - .prepend(wrapperIntro); - } - - var finalisers = { system: system, amd: amd, cjs: cjs, es: esm, iife: iife, umd: umd }; - - function getLocator$1(source, options) { - if (options === void 0) { options = {}; } - var offsetLine = options.offsetLine || 0; - var offsetColumn = options.offsetColumn || 0; - var originalLines = source.split('\n'); - var start = 0; - var lineRanges = originalLines.map(function (line, i) { - var end = start + line.length + 1; - var range = { start: start, end: end, line: i }; - start = end; - return range; - }); - var i = 0; - function rangeContains(range, index) { - return range.start <= index && index < range.end; - } - function getLocation(range, index) { - return { line: offsetLine + range.line, column: offsetColumn + index - range.start, character: index }; - } - function locate(search, startIndex) { - if (typeof search === 'string') { - search = source.indexOf(search, startIndex || 0); - } - var range = lineRanges[i]; - var d = search >= range.end ? 1 : -1; - while (range) { - if (rangeContains(range, search)) - return getLocation(range, search); - i += d; - range = lineRanges[i]; - } - } - return locate; - } - function locate(source, search, options) { - if (typeof options === 'number') { - throw new Error('locate takes a { startIndex, offsetLine, offsetColumn } object as the third argument'); - } - return getLocator$1(source, options)(search, options && options.startIndex); - } - - var BLANK = Object.create(null); - - var NO_SEMICOLON = { isNoStatement: true }; - function findFirstOccurrenceOutsideComment(code, searchString, start) { - if (start === void 0) { start = 0; } - var searchPos, charCodeAfterSlash; - searchPos = code.indexOf(searchString, start); - while (true) { - start = code.indexOf('/', start); - if (start === -1 || start > searchPos) - return searchPos; - charCodeAfterSlash = code.charCodeAt(++start); - ++start; - if (charCodeAfterSlash === 47 /*"/"*/) { - start = code.indexOf('\n', start) + 1; - if (start === 0) - return -1; - if (start > searchPos) { - searchPos = code.indexOf(searchString, start); - } - } - else if (charCodeAfterSlash === 42 /*"*"*/) { - start = code.indexOf('*/', start) + 2; - if (start > searchPos) { - searchPos = code.indexOf(searchString, start); - } - } - } - } - function findFirstLineBreakOutsideComment(code, start) { - if (start === void 0) { start = 0; } - var lineBreakPos, charCodeAfterSlash; - lineBreakPos = code.indexOf('\n', start); - while (true) { - start = code.indexOf('/', start); - if (start === -1 || start > lineBreakPos) - return lineBreakPos; - charCodeAfterSlash = code.charCodeAt(++start); - if (charCodeAfterSlash === 47 /*"/"*/) - return lineBreakPos; - ++start; - if (charCodeAfterSlash === 42 /*"*"*/) { - start = code.indexOf('*/', start) + 2; - if (start > lineBreakPos) { - lineBreakPos = code.indexOf('\n', start); - } - } - } - } - function renderStatementList(statements, code, start, end, options) { - if (statements.length === 0) - return; - var currentNode, currentNodeStart, currentNodeNeedsBoundaries, nextNodeStart; - var nextNode = statements[0]; - var nextNodeNeedsBoundaries = !nextNode.included || nextNode.needsBoundaries; - if (nextNodeNeedsBoundaries) { - nextNodeStart = - start + findFirstLineBreakOutsideComment(code.original.slice(start, nextNode.start)) + 1; - } - for (var nextIndex = 1; nextIndex <= statements.length; nextIndex++) { - currentNode = nextNode; - currentNodeStart = nextNodeStart; - currentNodeNeedsBoundaries = nextNodeNeedsBoundaries; - nextNode = statements[nextIndex]; - nextNodeNeedsBoundaries = - nextNode === undefined ? false : !nextNode.included || nextNode.needsBoundaries; - if (currentNodeNeedsBoundaries || nextNodeNeedsBoundaries) { - nextNodeStart = - currentNode.end + - findFirstLineBreakOutsideComment(code.original.slice(currentNode.end, nextNode === undefined ? end : nextNode.start)) + - 1; - if (currentNode.included) { - currentNodeNeedsBoundaries - ? currentNode.render(code, options, { - start: currentNodeStart, - end: nextNodeStart - }) - : currentNode.render(code, options); - } - else { - code.remove(currentNodeStart, nextNodeStart); - } - } - else { - currentNode.render(code, options); - } - } - } - // This assumes that the first character is not part of the first node - function getCommaSeparatedNodesWithBoundaries(nodes, code, start, end) { - var splitUpNodes = []; - var node, nextNode, nextNodeStart, contentEnd, char; - var separator = start - 1; - for (var nextIndex = 0; nextIndex < nodes.length; nextIndex++) { - nextNode = nodes[nextIndex]; - if (node !== undefined) { - separator = - node.end + - findFirstOccurrenceOutsideComment(code.original.slice(node.end, nextNode.start), ','); - } - nextNodeStart = contentEnd = - separator + - 2 + - findFirstLineBreakOutsideComment(code.original.slice(separator + 1, nextNode.start)); - while (((char = code.original.charCodeAt(nextNodeStart)), - char === 32 /*" "*/ || char === 9 /*"\t"*/ || char === 10 /*"\n"*/ || char === 13) /*"\r"*/) - nextNodeStart++; - if (node !== undefined) { - splitUpNodes.push({ - node: node, - start: start, - contentEnd: contentEnd, - separator: separator, - end: nextNodeStart - }); - } - node = nextNode; - start = nextNodeStart; - } - splitUpNodes.push({ - node: node, - start: start, - separator: null, - contentEnd: end, - end: end - }); - return splitUpNodes; - } - - var chars$1 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$'; - function toBase64(num, base63) { - if (base63 === void 0) { base63 = false; } - var outStr = ''; - var base = base63 ? 63 : 64; - do { - var curDigit = num % base; - num = Math.floor(num / base); - outStr = chars$1[curDigit] + outStr; - } while (num !== 0); - return outStr; - } - - var Scope = /** @class */ (function () { - function Scope(parent) { - if (parent === void 0) { parent = null; } - this.isModuleScope = false; - this.parent = parent; - this.children = []; - if (this.parent) - this.parent.children.push(this); - this.variables = Object.create(null); - } - Scope.prototype.addDeclaration = function (identifier, deoptimizationTracker, init, _isHoisted) { - if (init === void 0) { init = null; } - var name = identifier.name; - if (this.variables[name]) { - this.variables[name].addDeclaration(identifier, init); - } - else { - this.variables[name] = new LocalVariable(identifier.name, identifier, init || UNDEFINED_EXPRESSION, deoptimizationTracker); - } - return this.variables[name]; - }; - Scope.prototype.addExportDefaultDeclaration = function (name, exportDefaultDeclaration, deoptimizationTracker) { - this.variables.default = new ExportDefaultVariable(name, exportDefaultDeclaration, deoptimizationTracker); - return this.variables.default; - }; - Scope.prototype.addReturnExpression = function (expression) { - this.parent && this.parent.addReturnExpression(expression); - }; - Scope.prototype.contains = function (name) { - return name in this.variables || (this.parent ? this.parent.contains(name) : false); - }; - Scope.prototype.deshadow = function (names, children) { - if (children === void 0) { children = this.children; } - for (var _i = 0, _a = Object.keys(this.variables); _i < _a.length; _i++) { - var key = _a[_i]; - var declaration = this.variables[key]; - // we can disregard exports.foo etc - if (declaration.exportName && declaration.isReassigned && !declaration.isId) - continue; - if (declaration.isDefault) - continue; - var name = declaration.getName(true); - if (!names.has(name)) - continue; - name = declaration.name; - var deshadowed = void 0, i = 1; - do { - deshadowed = name + "$$" + toBase64(i++); - } while (names.has(deshadowed)); - declaration.setSafeName(deshadowed); - } - for (var _b = 0, children_1 = children; _b < children_1.length; _b++) { - var scope = children_1[_b]; - scope.deshadow(names); - } - }; - Scope.prototype.findLexicalBoundary = function () { - return this.parent.findLexicalBoundary(); - }; - Scope.prototype.findVariable = function (name) { - return this.variables[name] || (this.parent && this.parent.findVariable(name)); - }; - return Scope; - }()); - - var immutable = createCommonjsModule(function (module, exports) { - /** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - - (function (global, factory) { - module.exports = factory(); - }(commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice; - - function createClass(ctor, superClass) { - if (superClass) { - ctor.prototype = Object.create(superClass.prototype); - } - ctor.prototype.constructor = ctor; - } - - function Iterable(value) { - return isIterable(value) ? value : Seq(value); - } - - - createClass(KeyedIterable, Iterable); - function KeyedIterable(value) { - return isKeyed(value) ? value : KeyedSeq(value); - } - - - createClass(IndexedIterable, Iterable); - function IndexedIterable(value) { - return isIndexed(value) ? value : IndexedSeq(value); - } - - - createClass(SetIterable, Iterable); - function SetIterable(value) { - return isIterable(value) && !isAssociative(value) ? value : SetSeq(value); - } - - - - function isIterable(maybeIterable) { - return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]); - } - - function isKeyed(maybeKeyed) { - return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]); - } - - function isIndexed(maybeIndexed) { - return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]); - } - - function isAssociative(maybeAssociative) { - return isKeyed(maybeAssociative) || isIndexed(maybeAssociative); - } - - function isOrdered(maybeOrdered) { - return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]); - } - - Iterable.isIterable = isIterable; - Iterable.isKeyed = isKeyed; - Iterable.isIndexed = isIndexed; - Iterable.isAssociative = isAssociative; - Iterable.isOrdered = isOrdered; - - Iterable.Keyed = KeyedIterable; - Iterable.Indexed = IndexedIterable; - Iterable.Set = SetIterable; - - - var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@'; - var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@'; - var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@'; - var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@'; - - // Used for setting prototype methods that IE8 chokes on. - var DELETE = 'delete'; - - // Constants describing the size of trie nodes. - var SHIFT = 5; // Resulted in best performance after ______? - var SIZE = 1 << SHIFT; - var MASK = SIZE - 1; - - // A consistent shared value representing "not set" which equals nothing other - // than itself, and nothing that could be provided externally. - var NOT_SET = {}; - - // Boolean references, Rough equivalent of `bool &`. - var CHANGE_LENGTH = { value: false }; - var DID_ALTER = { value: false }; - - function MakeRef(ref) { - ref.value = false; - return ref; - } - - function SetRef(ref) { - ref && (ref.value = true); - } - - // A function which returns a value representing an "owner" for transient writes - // to tries. The return value will only ever equal itself, and will not equal - // the return of any subsequent call of this function. - function OwnerID() {} - - // http://jsperf.com/copy-array-inline - function arrCopy(arr, offset) { - offset = offset || 0; - var len = Math.max(0, arr.length - offset); - var newArr = new Array(len); - for (var ii = 0; ii < len; ii++) { - newArr[ii] = arr[ii + offset]; - } - return newArr; - } - - function ensureSize(iter) { - if (iter.size === undefined) { - iter.size = iter.__iterate(returnTrue); - } - return iter.size; - } - - function wrapIndex(iter, index) { - // This implements "is array index" which the ECMAString spec defines as: - // - // A String property name P is an array index if and only if - // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal - // to 2^32−1. - // - // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects - if (typeof index !== 'number') { - var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32 - if ('' + uint32Index !== index || uint32Index === 4294967295) { - return NaN; - } - index = uint32Index; - } - return index < 0 ? ensureSize(iter) + index : index; - } - - function returnTrue() { - return true; - } - - function wholeSlice(begin, end, size) { - return (begin === 0 || (size !== undefined && begin <= -size)) && - (end === undefined || (size !== undefined && end >= size)); - } - - function resolveBegin(begin, size) { - return resolveIndex(begin, size, 0); - } - - function resolveEnd(end, size) { - return resolveIndex(end, size, size); - } - - function resolveIndex(index, size, defaultIndex) { - return index === undefined ? - defaultIndex : - index < 0 ? - Math.max(0, size + index) : - size === undefined ? - index : - Math.min(size, index); - } - - /* global Symbol */ - - var ITERATE_KEYS = 0; - var ITERATE_VALUES = 1; - var ITERATE_ENTRIES = 2; - - var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; - var FAUX_ITERATOR_SYMBOL = '@@iterator'; - - var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL; - - - function Iterator(next) { - this.next = next; - } - - Iterator.prototype.toString = function() { - return '[Iterator]'; - }; - - - Iterator.KEYS = ITERATE_KEYS; - Iterator.VALUES = ITERATE_VALUES; - Iterator.ENTRIES = ITERATE_ENTRIES; - - Iterator.prototype.inspect = - Iterator.prototype.toSource = function () { return this.toString(); }; - Iterator.prototype[ITERATOR_SYMBOL] = function () { - return this; - }; - - - function iteratorValue(type, k, v, iteratorResult) { - var value = type === 0 ? k : type === 1 ? v : [k, v]; - iteratorResult ? (iteratorResult.value = value) : (iteratorResult = { - value: value, done: false - }); - return iteratorResult; - } - - function iteratorDone() { - return { value: undefined, done: true }; - } - - function hasIterator(maybeIterable) { - return !!getIteratorFn(maybeIterable); - } - - function isIterator(maybeIterator) { - return maybeIterator && typeof maybeIterator.next === 'function'; - } - - function getIterator(iterable) { - var iteratorFn = getIteratorFn(iterable); - return iteratorFn && iteratorFn.call(iterable); - } - - function getIteratorFn(iterable) { - var iteratorFn = iterable && ( - (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) || - iterable[FAUX_ITERATOR_SYMBOL] - ); - if (typeof iteratorFn === 'function') { - return iteratorFn; - } - } - - function isArrayLike(value) { - return value && typeof value.length === 'number'; - } - - createClass(Seq, Iterable); - function Seq(value) { - return value === null || value === undefined ? emptySequence() : - isIterable(value) ? value.toSeq() : seqFromValue(value); - } - - Seq.of = function(/*...values*/) { - return Seq(arguments); - }; - - Seq.prototype.toSeq = function() { - return this; - }; - - Seq.prototype.toString = function() { - return this.__toString('Seq {', '}'); - }; - - Seq.prototype.cacheResult = function() { - if (!this._cache && this.__iterateUncached) { - this._cache = this.entrySeq().toArray(); - this.size = this._cache.length; - } - return this; - }; - - // abstract __iterateUncached(fn, reverse) - - Seq.prototype.__iterate = function(fn, reverse) { - return seqIterate(this, fn, reverse, true); - }; - - // abstract __iteratorUncached(type, reverse) - - Seq.prototype.__iterator = function(type, reverse) { - return seqIterator(this, type, reverse, true); - }; - - - - createClass(KeyedSeq, Seq); - function KeyedSeq(value) { - return value === null || value === undefined ? - emptySequence().toKeyedSeq() : - isIterable(value) ? - (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) : - keyedSeqFromValue(value); - } - - KeyedSeq.prototype.toKeyedSeq = function() { - return this; - }; - - - - createClass(IndexedSeq, Seq); - function IndexedSeq(value) { - return value === null || value === undefined ? emptySequence() : - !isIterable(value) ? indexedSeqFromValue(value) : - isKeyed(value) ? value.entrySeq() : value.toIndexedSeq(); - } - - IndexedSeq.of = function(/*...values*/) { - return IndexedSeq(arguments); - }; - - IndexedSeq.prototype.toIndexedSeq = function() { - return this; - }; - - IndexedSeq.prototype.toString = function() { - return this.__toString('Seq [', ']'); - }; - - IndexedSeq.prototype.__iterate = function(fn, reverse) { - return seqIterate(this, fn, reverse, false); - }; - - IndexedSeq.prototype.__iterator = function(type, reverse) { - return seqIterator(this, type, reverse, false); - }; - - - - createClass(SetSeq, Seq); - function SetSeq(value) { - return ( - value === null || value === undefined ? emptySequence() : - !isIterable(value) ? indexedSeqFromValue(value) : - isKeyed(value) ? value.entrySeq() : value - ).toSetSeq(); - } - - SetSeq.of = function(/*...values*/) { - return SetSeq(arguments); - }; - - SetSeq.prototype.toSetSeq = function() { - return this; - }; - - - - Seq.isSeq = isSeq; - Seq.Keyed = KeyedSeq; - Seq.Set = SetSeq; - Seq.Indexed = IndexedSeq; - - var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@'; - - Seq.prototype[IS_SEQ_SENTINEL] = true; - - - - createClass(ArraySeq, IndexedSeq); - function ArraySeq(array) { - this._array = array; - this.size = array.length; - } - - ArraySeq.prototype.get = function(index, notSetValue) { - return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue; - }; - - ArraySeq.prototype.__iterate = function(fn, reverse) { - var array = this._array; - var maxIndex = array.length - 1; - for (var ii = 0; ii <= maxIndex; ii++) { - if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) { - return ii + 1; - } - } - return ii; - }; - - ArraySeq.prototype.__iterator = function(type, reverse) { - var array = this._array; - var maxIndex = array.length - 1; - var ii = 0; - return new Iterator(function() - {return ii > maxIndex ? - iteratorDone() : - iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])} - ); - }; - - - - createClass(ObjectSeq, KeyedSeq); - function ObjectSeq(object) { - var keys = Object.keys(object); - this._object = object; - this._keys = keys; - this.size = keys.length; - } - - ObjectSeq.prototype.get = function(key, notSetValue) { - if (notSetValue !== undefined && !this.has(key)) { - return notSetValue; - } - return this._object[key]; - }; - - ObjectSeq.prototype.has = function(key) { - return this._object.hasOwnProperty(key); - }; - - ObjectSeq.prototype.__iterate = function(fn, reverse) { - var object = this._object; - var keys = this._keys; - var maxIndex = keys.length - 1; - for (var ii = 0; ii <= maxIndex; ii++) { - var key = keys[reverse ? maxIndex - ii : ii]; - if (fn(object[key], key, this) === false) { - return ii + 1; - } - } - return ii; - }; - - ObjectSeq.prototype.__iterator = function(type, reverse) { - var object = this._object; - var keys = this._keys; - var maxIndex = keys.length - 1; - var ii = 0; - return new Iterator(function() { - var key = keys[reverse ? maxIndex - ii : ii]; - return ii++ > maxIndex ? - iteratorDone() : - iteratorValue(type, key, object[key]); - }); - }; - - ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true; - - - createClass(IterableSeq, IndexedSeq); - function IterableSeq(iterable) { - this._iterable = iterable; - this.size = iterable.length || iterable.size; - } - - IterableSeq.prototype.__iterateUncached = function(fn, reverse) { - if (reverse) { - return this.cacheResult().__iterate(fn, reverse); - } - var iterable = this._iterable; - var iterator = getIterator(iterable); - var iterations = 0; - if (isIterator(iterator)) { - var step; - while (!(step = iterator.next()).done) { - if (fn(step.value, iterations++, this) === false) { - break; - } - } - } - return iterations; - }; - - IterableSeq.prototype.__iteratorUncached = function(type, reverse) { - if (reverse) { - return this.cacheResult().__iterator(type, reverse); - } - var iterable = this._iterable; - var iterator = getIterator(iterable); - if (!isIterator(iterator)) { - return new Iterator(iteratorDone); - } - var iterations = 0; - return new Iterator(function() { - var step = iterator.next(); - return step.done ? step : iteratorValue(type, iterations++, step.value); - }); - }; - - - - createClass(IteratorSeq, IndexedSeq); - function IteratorSeq(iterator) { - this._iterator = iterator; - this._iteratorCache = []; - } - - IteratorSeq.prototype.__iterateUncached = function(fn, reverse) { - if (reverse) { - return this.cacheResult().__iterate(fn, reverse); - } - var iterator = this._iterator; - var cache = this._iteratorCache; - var iterations = 0; - while (iterations < cache.length) { - if (fn(cache[iterations], iterations++, this) === false) { - return iterations; - } - } - var step; - while (!(step = iterator.next()).done) { - var val = step.value; - cache[iterations] = val; - if (fn(val, iterations++, this) === false) { - break; - } - } - return iterations; - }; - - IteratorSeq.prototype.__iteratorUncached = function(type, reverse) { - if (reverse) { - return this.cacheResult().__iterator(type, reverse); - } - var iterator = this._iterator; - var cache = this._iteratorCache; - var iterations = 0; - return new Iterator(function() { - if (iterations >= cache.length) { - var step = iterator.next(); - if (step.done) { - return step; - } - cache[iterations] = step.value; - } - return iteratorValue(type, iterations, cache[iterations++]); - }); - }; - - - - - // # pragma Helper functions - - function isSeq(maybeSeq) { - return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]); - } - - var EMPTY_SEQ; - - function emptySequence() { - return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([])); - } - - function keyedSeqFromValue(value) { - var seq = - Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() : - isIterator(value) ? new IteratorSeq(value).fromEntrySeq() : - hasIterator(value) ? new IterableSeq(value).fromEntrySeq() : - typeof value === 'object' ? new ObjectSeq(value) : - undefined; - if (!seq) { - throw new TypeError( - 'Expected Array or iterable object of [k, v] entries, '+ - 'or keyed object: ' + value - ); - } - return seq; - } - - function indexedSeqFromValue(value) { - var seq = maybeIndexedSeqFromValue(value); - if (!seq) { - throw new TypeError( - 'Expected Array or iterable object of values: ' + value - ); - } - return seq; - } - - function seqFromValue(value) { - var seq = maybeIndexedSeqFromValue(value) || - (typeof value === 'object' && new ObjectSeq(value)); - if (!seq) { - throw new TypeError( - 'Expected Array or iterable object of values, or keyed object: ' + value - ); - } - return seq; - } - - function maybeIndexedSeqFromValue(value) { - return ( - isArrayLike(value) ? new ArraySeq(value) : - isIterator(value) ? new IteratorSeq(value) : - hasIterator(value) ? new IterableSeq(value) : - undefined - ); - } - - function seqIterate(seq, fn, reverse, useKeys) { - var cache = seq._cache; - if (cache) { - var maxIndex = cache.length - 1; - for (var ii = 0; ii <= maxIndex; ii++) { - var entry = cache[reverse ? maxIndex - ii : ii]; - if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) { - return ii + 1; - } - } - return ii; - } - return seq.__iterateUncached(fn, reverse); - } - - function seqIterator(seq, type, reverse, useKeys) { - var cache = seq._cache; - if (cache) { - var maxIndex = cache.length - 1; - var ii = 0; - return new Iterator(function() { - var entry = cache[reverse ? maxIndex - ii : ii]; - return ii++ > maxIndex ? - iteratorDone() : - iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]); - }); - } - return seq.__iteratorUncached(type, reverse); - } - - function fromJS(json, converter) { - return converter ? - fromJSWith(converter, json, '', {'': json}) : - fromJSDefault(json); - } - - function fromJSWith(converter, json, key, parentJSON) { - if (Array.isArray(json)) { - return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)})); - } - if (isPlainObj(json)) { - return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)})); - } - return json; - } - - function fromJSDefault(json) { - if (Array.isArray(json)) { - return IndexedSeq(json).map(fromJSDefault).toList(); - } - if (isPlainObj(json)) { - return KeyedSeq(json).map(fromJSDefault).toMap(); - } - return json; - } - - function isPlainObj(value) { - return value && (value.constructor === Object || value.constructor === undefined); - } - - /** - * An extension of the "same-value" algorithm as [described for use by ES6 Map - * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality) - * - * NaN is considered the same as NaN, however -0 and 0 are considered the same - * value, which is different from the algorithm described by - * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is). - * - * This is extended further to allow Objects to describe the values they - * represent, by way of `valueOf` or `equals` (and `hashCode`). - * - * Note: because of this extension, the key equality of Immutable.Map and the - * value equality of Immutable.Set will differ from ES6 Map and Set. - * - * ### Defining custom values - * - * The easiest way to describe the value an object represents is by implementing - * `valueOf`. For example, `Date` represents a value by returning a unix - * timestamp for `valueOf`: - * - * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ... - * var date2 = new Date(1234567890000); - * date1.valueOf(); // 1234567890000 - * assert( date1 !== date2 ); - * assert( Immutable.is( date1, date2 ) ); - * - * Note: overriding `valueOf` may have other implications if you use this object - * where JavaScript expects a primitive, such as implicit string coercion. - * - * For more complex types, especially collections, implementing `valueOf` may - * not be performant. An alternative is to implement `equals` and `hashCode`. - * - * `equals` takes another object, presumably of similar type, and returns true - * if the it is equal. Equality is symmetrical, so the same result should be - * returned if this and the argument are flipped. - * - * assert( a.equals(b) === b.equals(a) ); - * - * `hashCode` returns a 32bit integer number representing the object which will - * be used to determine how to store the value object in a Map or Set. You must - * provide both or neither methods, one must not exist without the other. - * - * Also, an important relationship between these methods must be upheld: if two - * values are equal, they *must* return the same hashCode. If the values are not - * equal, they might have the same hashCode; this is called a hash collision, - * and while undesirable for performance reasons, it is acceptable. - * - * if (a.equals(b)) { - * assert( a.hashCode() === b.hashCode() ); - * } - * - * All Immutable collections implement `equals` and `hashCode`. - * - */ - function is(valueA, valueB) { - if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) { - return true; - } - if (!valueA || !valueB) { - return false; - } - if (typeof valueA.valueOf === 'function' && - typeof valueB.valueOf === 'function') { - valueA = valueA.valueOf(); - valueB = valueB.valueOf(); - if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) { - return true; - } - if (!valueA || !valueB) { - return false; - } - } - if (typeof valueA.equals === 'function' && - typeof valueB.equals === 'function' && - valueA.equals(valueB)) { - return true; - } - return false; - } - - function deepEqual(a, b) { - if (a === b) { - return true; - } - - if ( - !isIterable(b) || - a.size !== undefined && b.size !== undefined && a.size !== b.size || - a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash || - isKeyed(a) !== isKeyed(b) || - isIndexed(a) !== isIndexed(b) || - isOrdered(a) !== isOrdered(b) - ) { - return false; - } - - if (a.size === 0 && b.size === 0) { - return true; - } - - var notAssociative = !isAssociative(a); - - if (isOrdered(a)) { - var entries = a.entries(); - return b.every(function(v, k) { - var entry = entries.next().value; - return entry && is(entry[1], v) && (notAssociative || is(entry[0], k)); - }) && entries.next().done; - } - - var flipped = false; - - if (a.size === undefined) { - if (b.size === undefined) { - if (typeof a.cacheResult === 'function') { - a.cacheResult(); - } - } else { - flipped = true; - var _ = a; - a = b; - b = _; - } - } - - var allEqual = true; - var bSize = b.__iterate(function(v, k) { - if (notAssociative ? !a.has(v) : - flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) { - allEqual = false; - return false; - } - }); - - return allEqual && a.size === bSize; - } - - createClass(Repeat, IndexedSeq); - - function Repeat(value, times) { - if (!(this instanceof Repeat)) { - return new Repeat(value, times); - } - this._value = value; - this.size = times === undefined ? Infinity : Math.max(0, times); - if (this.size === 0) { - if (EMPTY_REPEAT) { - return EMPTY_REPEAT; - } - EMPTY_REPEAT = this; - } - } - - Repeat.prototype.toString = function() { - if (this.size === 0) { - return 'Repeat []'; - } - return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]'; - }; - - Repeat.prototype.get = function(index, notSetValue) { - return this.has(index) ? this._value : notSetValue; - }; - - Repeat.prototype.includes = function(searchValue) { - return is(this._value, searchValue); - }; - - Repeat.prototype.slice = function(begin, end) { - var size = this.size; - return wholeSlice(begin, end, size) ? this : - new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size)); - }; - - Repeat.prototype.reverse = function() { - return this; - }; - - Repeat.prototype.indexOf = function(searchValue) { - if (is(this._value, searchValue)) { - return 0; - } - return -1; - }; - - Repeat.prototype.lastIndexOf = function(searchValue) { - if (is(this._value, searchValue)) { - return this.size; - } - return -1; - }; - - Repeat.prototype.__iterate = function(fn, reverse) { - for (var ii = 0; ii < this.size; ii++) { - if (fn(this._value, ii, this) === false) { - return ii + 1; - } - } - return ii; - }; - - Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this; - var ii = 0; - return new Iterator(function() - {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()} - ); - }; - - Repeat.prototype.equals = function(other) { - return other instanceof Repeat ? - is(this._value, other._value) : - deepEqual(other); - }; - - - var EMPTY_REPEAT; - - function invariant(condition, error) { - if (!condition) throw new Error(error); - } - - createClass(Range, IndexedSeq); - - function Range(start, end, step) { - if (!(this instanceof Range)) { - return new Range(start, end, step); - } - invariant(step !== 0, 'Cannot step a Range by 0'); - start = start || 0; - if (end === undefined) { - end = Infinity; - } - step = step === undefined ? 1 : Math.abs(step); - if (end < start) { - step = -step; - } - this._start = start; - this._end = end; - this._step = step; - this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1); - if (this.size === 0) { - if (EMPTY_RANGE) { - return EMPTY_RANGE; - } - EMPTY_RANGE = this; - } - } - - Range.prototype.toString = function() { - if (this.size === 0) { - return 'Range []'; - } - return 'Range [ ' + - this._start + '...' + this._end + - (this._step !== 1 ? ' by ' + this._step : '') + - ' ]'; - }; - - Range.prototype.get = function(index, notSetValue) { - return this.has(index) ? - this._start + wrapIndex(this, index) * this._step : - notSetValue; - }; - - Range.prototype.includes = function(searchValue) { - var possibleIndex = (searchValue - this._start) / this._step; - return possibleIndex >= 0 && - possibleIndex < this.size && - possibleIndex === Math.floor(possibleIndex); - }; - - Range.prototype.slice = function(begin, end) { - if (wholeSlice(begin, end, this.size)) { - return this; - } - begin = resolveBegin(begin, this.size); - end = resolveEnd(end, this.size); - if (end <= begin) { - return new Range(0, 0); - } - return new Range(this.get(begin, this._end), this.get(end, this._end), this._step); - }; - - Range.prototype.indexOf = function(searchValue) { - var offsetValue = searchValue - this._start; - if (offsetValue % this._step === 0) { - var index = offsetValue / this._step; - if (index >= 0 && index < this.size) { - return index - } - } - return -1; - }; - - Range.prototype.lastIndexOf = function(searchValue) { - return this.indexOf(searchValue); - }; - - Range.prototype.__iterate = function(fn, reverse) { - var maxIndex = this.size - 1; - var step = this._step; - var value = reverse ? this._start + maxIndex * step : this._start; - for (var ii = 0; ii <= maxIndex; ii++) { - if (fn(value, ii, this) === false) { - return ii + 1; - } - value += reverse ? -step : step; - } - return ii; - }; - - Range.prototype.__iterator = function(type, reverse) { - var maxIndex = this.size - 1; - var step = this._step; - var value = reverse ? this._start + maxIndex * step : this._start; - var ii = 0; - return new Iterator(function() { - var v = value; - value += reverse ? -step : step; - return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v); - }); - }; - - Range.prototype.equals = function(other) { - return other instanceof Range ? - this._start === other._start && - this._end === other._end && - this._step === other._step : - deepEqual(this, other); - }; - - - var EMPTY_RANGE; - - createClass(Collection, Iterable); - function Collection() { - throw TypeError('Abstract'); - } - - - createClass(KeyedCollection, Collection);function KeyedCollection() {} - - createClass(IndexedCollection, Collection);function IndexedCollection() {} - - createClass(SetCollection, Collection);function SetCollection() {} - - - Collection.Keyed = KeyedCollection; - Collection.Indexed = IndexedCollection; - Collection.Set = SetCollection; - - var imul = - typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ? - Math.imul : - function imul(a, b) { - a = a | 0; // int - b = b | 0; // int - var c = a & 0xffff; - var d = b & 0xffff; - // Shift by 0 fixes the sign on the high part. - return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int - }; - - // v8 has an optimization for storing 31-bit signed numbers. - // Values which have either 00 or 11 as the high order bits qualify. - // This function drops the highest order bit in a signed number, maintaining - // the sign bit. - function smi(i32) { - return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF); - } - - function hash(o) { - if (o === false || o === null || o === undefined) { - return 0; - } - if (typeof o.valueOf === 'function') { - o = o.valueOf(); - if (o === false || o === null || o === undefined) { - return 0; - } - } - if (o === true) { - return 1; - } - var type = typeof o; - if (type === 'number') { - if (o !== o || o === Infinity) { - return 0; - } - var h = o | 0; - if (h !== o) { - h ^= o * 0xFFFFFFFF; - } - while (o > 0xFFFFFFFF) { - o /= 0xFFFFFFFF; - h ^= o; - } - return smi(h); - } - if (type === 'string') { - return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o); - } - if (typeof o.hashCode === 'function') { - return o.hashCode(); - } - if (type === 'object') { - return hashJSObj(o); - } - if (typeof o.toString === 'function') { - return hashString(o.toString()); - } - throw new Error('Value type ' + type + ' cannot be hashed.'); - } - - function cachedHashString(string) { - var hash = stringHashCache[string]; - if (hash === undefined) { - hash = hashString(string); - if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) { - STRING_HASH_CACHE_SIZE = 0; - stringHashCache = {}; - } - STRING_HASH_CACHE_SIZE++; - stringHashCache[string] = hash; - } - return hash; - } - - // http://jsperf.com/hashing-strings - function hashString(string) { - // This is the hash from JVM - // The hash code for a string is computed as - // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1], - // where s[i] is the ith character of the string and n is the length of - // the string. We "mod" the result to make it between 0 (inclusive) and 2^31 - // (exclusive) by dropping high bits. - var hash = 0; - for (var ii = 0; ii < string.length; ii++) { - hash = 31 * hash + string.charCodeAt(ii) | 0; - } - return smi(hash); - } - - function hashJSObj(obj) { - var hash; - if (usingWeakMap) { - hash = weakMap.get(obj); - if (hash !== undefined) { - return hash; - } - } - - hash = obj[UID_HASH_KEY]; - if (hash !== undefined) { - return hash; - } - - if (!canDefineProperty) { - hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY]; - if (hash !== undefined) { - return hash; - } - - hash = getIENodeHash(obj); - if (hash !== undefined) { - return hash; - } - } - - hash = ++objHashUID; - if (objHashUID & 0x40000000) { - objHashUID = 0; - } - - if (usingWeakMap) { - weakMap.set(obj, hash); - } else if (isExtensible !== undefined && isExtensible(obj) === false) { - throw new Error('Non-extensible objects are not allowed as keys.'); - } else if (canDefineProperty) { - Object.defineProperty(obj, UID_HASH_KEY, { - 'enumerable': false, - 'configurable': false, - 'writable': false, - 'value': hash - }); - } else if (obj.propertyIsEnumerable !== undefined && - obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) { - // Since we can't define a non-enumerable property on the object - // we'll hijack one of the less-used non-enumerable properties to - // save our hash on it. Since this is a function it will not show up in - // `JSON.stringify` which is what we want. - obj.propertyIsEnumerable = function() { - return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments); - }; - obj.propertyIsEnumerable[UID_HASH_KEY] = hash; - } else if (obj.nodeType !== undefined) { - // At this point we couldn't get the IE `uniqueID` to use as a hash - // and we couldn't use a non-enumerable property to exploit the - // dontEnum bug so we simply add the `UID_HASH_KEY` on the node - // itself. - obj[UID_HASH_KEY] = hash; - } else { - throw new Error('Unable to set a non-enumerable property on object.'); - } - - return hash; - } - - // Get references to ES5 object methods. - var isExtensible = Object.isExtensible; - - // True if Object.defineProperty works as expected. IE8 fails this test. - var canDefineProperty = (function() { - try { - Object.defineProperty({}, '@', {}); - return true; - } catch (e) { - return false; - } - }()); - - // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it - // and avoid memory leaks from the IE cloneNode bug. - function getIENodeHash(node) { - if (node && node.nodeType > 0) { - switch (node.nodeType) { - case 1: // Element - return node.uniqueID; - case 9: // Document - return node.documentElement && node.documentElement.uniqueID; - } - } - } - - // If possible, use a WeakMap. - var usingWeakMap = typeof WeakMap === 'function'; - var weakMap; - if (usingWeakMap) { - weakMap = new WeakMap(); - } - - var objHashUID = 0; - - var UID_HASH_KEY = '__immutablehash__'; - if (typeof Symbol === 'function') { - UID_HASH_KEY = Symbol(UID_HASH_KEY); - } - - var STRING_HASH_CACHE_MIN_STRLEN = 16; - var STRING_HASH_CACHE_MAX_SIZE = 255; - var STRING_HASH_CACHE_SIZE = 0; - var stringHashCache = {}; - - function assertNotInfinite(size) { - invariant( - size !== Infinity, - 'Cannot perform this action with an infinite size.' - ); - } - - createClass(Map, KeyedCollection); - - // @pragma Construction - - function Map(value) { - return value === null || value === undefined ? emptyMap() : - isMap(value) && !isOrdered(value) ? value : - emptyMap().withMutations(function(map ) { - var iter = KeyedIterable(value); - assertNotInfinite(iter.size); - iter.forEach(function(v, k) {return map.set(k, v)}); - }); - } - - Map.of = function() {var keyValues = SLICE$0.call(arguments, 0); - return emptyMap().withMutations(function(map ) { - for (var i = 0; i < keyValues.length; i += 2) { - if (i + 1 >= keyValues.length) { - throw new Error('Missing value for key: ' + keyValues[i]); - } - map.set(keyValues[i], keyValues[i + 1]); - } - }); - }; - - Map.prototype.toString = function() { - return this.__toString('Map {', '}'); - }; - - // @pragma Access - - Map.prototype.get = function(k, notSetValue) { - return this._root ? - this._root.get(0, undefined, k, notSetValue) : - notSetValue; - }; - - // @pragma Modification - - Map.prototype.set = function(k, v) { - return updateMap(this, k, v); - }; - - Map.prototype.setIn = function(keyPath, v) { - return this.updateIn(keyPath, NOT_SET, function() {return v}); - }; - - Map.prototype.remove = function(k) { - return updateMap(this, k, NOT_SET); - }; - - Map.prototype.deleteIn = function(keyPath) { - return this.updateIn(keyPath, function() {return NOT_SET}); - }; - - Map.prototype.update = function(k, notSetValue, updater) { - return arguments.length === 1 ? - k(this) : - this.updateIn([k], notSetValue, updater); - }; - - Map.prototype.updateIn = function(keyPath, notSetValue, updater) { - if (!updater) { - updater = notSetValue; - notSetValue = undefined; - } - var updatedValue = updateInDeepMap( - this, - forceIterator(keyPath), - notSetValue, - updater - ); - return updatedValue === NOT_SET ? undefined : updatedValue; - }; - - Map.prototype.clear = function() { - if (this.size === 0) { - return this; - } - if (this.__ownerID) { - this.size = 0; - this._root = null; - this.__hash = undefined; - this.__altered = true; - return this; - } - return emptyMap(); - }; - - // @pragma Composition - - Map.prototype.merge = function(/*...iters*/) { - return mergeIntoMapWith(this, undefined, arguments); - }; - - Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1); - return mergeIntoMapWith(this, merger, iters); - }; - - Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1); - return this.updateIn( - keyPath, - emptyMap(), - function(m ) {return typeof m.merge === 'function' ? - m.merge.apply(m, iters) : - iters[iters.length - 1]} - ); - }; - - Map.prototype.mergeDeep = function(/*...iters*/) { - return mergeIntoMapWith(this, deepMerger, arguments); - }; - - Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1); - return mergeIntoMapWith(this, deepMergerWith(merger), iters); - }; - - Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1); - return this.updateIn( - keyPath, - emptyMap(), - function(m ) {return typeof m.mergeDeep === 'function' ? - m.mergeDeep.apply(m, iters) : - iters[iters.length - 1]} - ); - }; - - Map.prototype.sort = function(comparator) { - // Late binding - return OrderedMap(sortFactory(this, comparator)); - }; - - Map.prototype.sortBy = function(mapper, comparator) { - // Late binding - return OrderedMap(sortFactory(this, comparator, mapper)); - }; - - // @pragma Mutability - - Map.prototype.withMutations = function(fn) { - var mutable = this.asMutable(); - fn(mutable); - return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this; - }; - - Map.prototype.asMutable = function() { - return this.__ownerID ? this : this.__ensureOwner(new OwnerID()); - }; - - Map.prototype.asImmutable = function() { - return this.__ensureOwner(); - }; - - Map.prototype.wasAltered = function() { - return this.__altered; - }; - - Map.prototype.__iterator = function(type, reverse) { - return new MapIterator(this, type, reverse); - }; - - Map.prototype.__iterate = function(fn, reverse) {var this$0 = this; - var iterations = 0; - this._root && this._root.iterate(function(entry ) { - iterations++; - return fn(entry[1], entry[0], this$0); - }, reverse); - return iterations; - }; - - Map.prototype.__ensureOwner = function(ownerID) { - if (ownerID === this.__ownerID) { - return this; - } - if (!ownerID) { - this.__ownerID = ownerID; - this.__altered = false; - return this; - } - return makeMap(this.size, this._root, ownerID, this.__hash); - }; - - - function isMap(maybeMap) { - return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]); - } - - Map.isMap = isMap; - - var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@'; - - var MapPrototype = Map.prototype; - MapPrototype[IS_MAP_SENTINEL] = true; - MapPrototype[DELETE] = MapPrototype.remove; - MapPrototype.removeIn = MapPrototype.deleteIn; - - - // #pragma Trie Nodes - - - - function ArrayMapNode(ownerID, entries) { - this.ownerID = ownerID; - this.entries = entries; - } - - ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) { - var entries = this.entries; - for (var ii = 0, len = entries.length; ii < len; ii++) { - if (is(key, entries[ii][0])) { - return entries[ii][1]; - } - } - return notSetValue; - }; - - ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) { - var removed = value === NOT_SET; - - var entries = this.entries; - var idx = 0; - for (var len = entries.length; idx < len; idx++) { - if (is(key, entries[idx][0])) { - break; - } - } - var exists = idx < len; - - if (exists ? entries[idx][1] === value : removed) { - return this; - } - - SetRef(didAlter); - (removed || !exists) && SetRef(didChangeSize); - - if (removed && entries.length === 1) { - return; // undefined - } - - if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) { - return createNodes(ownerID, entries, key, value); - } - - var isEditable = ownerID && ownerID === this.ownerID; - var newEntries = isEditable ? entries : arrCopy(entries); - - if (exists) { - if (removed) { - idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop()); - } else { - newEntries[idx] = [key, value]; - } - } else { - newEntries.push([key, value]); - } - - if (isEditable) { - this.entries = newEntries; - return this; - } - - return new ArrayMapNode(ownerID, newEntries); - }; - - - - - function BitmapIndexedNode(ownerID, bitmap, nodes) { - this.ownerID = ownerID; - this.bitmap = bitmap; - this.nodes = nodes; - } - - BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) { - if (keyHash === undefined) { - keyHash = hash(key); - } - var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK)); - var bitmap = this.bitmap; - return (bitmap & bit) === 0 ? notSetValue : - this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue); - }; - - BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) { - if (keyHash === undefined) { - keyHash = hash(key); - } - var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK; - var bit = 1 << keyHashFrag; - var bitmap = this.bitmap; - var exists = (bitmap & bit) !== 0; - - if (!exists && value === NOT_SET) { - return this; - } - - var idx = popCount(bitmap & (bit - 1)); - var nodes = this.nodes; - var node = exists ? nodes[idx] : undefined; - var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter); - - if (newNode === node) { - return this; - } - - if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) { - return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode); - } - - if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) { - return nodes[idx ^ 1]; - } - - if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) { - return newNode; - } - - var isEditable = ownerID && ownerID === this.ownerID; - var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit; - var newNodes = exists ? newNode ? - setIn(nodes, idx, newNode, isEditable) : - spliceOut(nodes, idx, isEditable) : - spliceIn(nodes, idx, newNode, isEditable); - - if (isEditable) { - this.bitmap = newBitmap; - this.nodes = newNodes; - return this; - } - - return new BitmapIndexedNode(ownerID, newBitmap, newNodes); - }; - - - - - function HashArrayMapNode(ownerID, count, nodes) { - this.ownerID = ownerID; - this.count = count; - this.nodes = nodes; - } - - HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) { - if (keyHash === undefined) { - keyHash = hash(key); - } - var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK; - var node = this.nodes[idx]; - return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue; - }; - - HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) { - if (keyHash === undefined) { - keyHash = hash(key); - } - var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK; - var removed = value === NOT_SET; - var nodes = this.nodes; - var node = nodes[idx]; - - if (removed && !node) { - return this; - } - - var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter); - if (newNode === node) { - return this; - } - - var newCount = this.count; - if (!node) { - newCount++; - } else if (!newNode) { - newCount--; - if (newCount < MIN_HASH_ARRAY_MAP_SIZE) { - return packNodes(ownerID, nodes, newCount, idx); - } - } - - var isEditable = ownerID && ownerID === this.ownerID; - var newNodes = setIn(nodes, idx, newNode, isEditable); - - if (isEditable) { - this.count = newCount; - this.nodes = newNodes; - return this; - } - - return new HashArrayMapNode(ownerID, newCount, newNodes); - }; - - - - - function HashCollisionNode(ownerID, keyHash, entries) { - this.ownerID = ownerID; - this.keyHash = keyHash; - this.entries = entries; - } - - HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) { - var entries = this.entries; - for (var ii = 0, len = entries.length; ii < len; ii++) { - if (is(key, entries[ii][0])) { - return entries[ii][1]; - } - } - return notSetValue; - }; - - HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) { - if (keyHash === undefined) { - keyHash = hash(key); - } - - var removed = value === NOT_SET; - - if (keyHash !== this.keyHash) { - if (removed) { - return this; - } - SetRef(didAlter); - SetRef(didChangeSize); - return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]); - } - - var entries = this.entries; - var idx = 0; - for (var len = entries.length; idx < len; idx++) { - if (is(key, entries[idx][0])) { - break; - } - } - var exists = idx < len; - - if (exists ? entries[idx][1] === value : removed) { - return this; - } - - SetRef(didAlter); - (removed || !exists) && SetRef(didChangeSize); - - if (removed && len === 2) { - return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]); - } - - var isEditable = ownerID && ownerID === this.ownerID; - var newEntries = isEditable ? entries : arrCopy(entries); - - if (exists) { - if (removed) { - idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop()); - } else { - newEntries[idx] = [key, value]; - } - } else { - newEntries.push([key, value]); - } - - if (isEditable) { - this.entries = newEntries; - return this; - } - - return new HashCollisionNode(ownerID, this.keyHash, newEntries); - }; - - - - - function ValueNode(ownerID, keyHash, entry) { - this.ownerID = ownerID; - this.keyHash = keyHash; - this.entry = entry; - } - - ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) { - return is(key, this.entry[0]) ? this.entry[1] : notSetValue; - }; - - ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) { - var removed = value === NOT_SET; - var keyMatch = is(key, this.entry[0]); - if (keyMatch ? value === this.entry[1] : removed) { - return this; - } - - SetRef(didAlter); - - if (removed) { - SetRef(didChangeSize); - return; // undefined - } - - if (keyMatch) { - if (ownerID && ownerID === this.ownerID) { - this.entry[1] = value; - return this; - } - return new ValueNode(ownerID, this.keyHash, [key, value]); - } - - SetRef(didChangeSize); - return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]); - }; - - - - // #pragma Iterators - - ArrayMapNode.prototype.iterate = - HashCollisionNode.prototype.iterate = function (fn, reverse) { - var entries = this.entries; - for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) { - if (fn(entries[reverse ? maxIndex - ii : ii]) === false) { - return false; - } - } - }; - - BitmapIndexedNode.prototype.iterate = - HashArrayMapNode.prototype.iterate = function (fn, reverse) { - var nodes = this.nodes; - for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) { - var node = nodes[reverse ? maxIndex - ii : ii]; - if (node && node.iterate(fn, reverse) === false) { - return false; - } - } - }; - - ValueNode.prototype.iterate = function (fn, reverse) { - return fn(this.entry); - }; - - createClass(MapIterator, Iterator); - - function MapIterator(map, type, reverse) { - this._type = type; - this._reverse = reverse; - this._stack = map._root && mapIteratorFrame(map._root); - } - - MapIterator.prototype.next = function() { - var type = this._type; - var stack = this._stack; - while (stack) { - var node = stack.node; - var index = stack.index++; - var maxIndex; - if (node.entry) { - if (index === 0) { - return mapIteratorValue(type, node.entry); - } - } else if (node.entries) { - maxIndex = node.entries.length - 1; - if (index <= maxIndex) { - return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]); - } - } else { - maxIndex = node.nodes.length - 1; - if (index <= maxIndex) { - var subNode = node.nodes[this._reverse ? maxIndex - index : index]; - if (subNode) { - if (subNode.entry) { - return mapIteratorValue(type, subNode.entry); - } - stack = this._stack = mapIteratorFrame(subNode, stack); - } - continue; - } - } - stack = this._stack = this._stack.__prev; - } - return iteratorDone(); - }; - - - function mapIteratorValue(type, entry) { - return iteratorValue(type, entry[0], entry[1]); - } - - function mapIteratorFrame(node, prev) { - return { - node: node, - index: 0, - __prev: prev - }; - } - - function makeMap(size, root, ownerID, hash) { - var map = Object.create(MapPrototype); - map.size = size; - map._root = root; - map.__ownerID = ownerID; - map.__hash = hash; - map.__altered = false; - return map; - } - - var EMPTY_MAP; - function emptyMap() { - return EMPTY_MAP || (EMPTY_MAP = makeMap(0)); - } - - function updateMap(map, k, v) { - var newRoot; - var newSize; - if (!map._root) { - if (v === NOT_SET) { - return map; - } - newSize = 1; - newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]); - } else { - var didChangeSize = MakeRef(CHANGE_LENGTH); - var didAlter = MakeRef(DID_ALTER); - newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter); - if (!didAlter.value) { - return map; - } - newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0); - } - if (map.__ownerID) { - map.size = newSize; - map._root = newRoot; - map.__hash = undefined; - map.__altered = true; - return map; - } - return newRoot ? makeMap(newSize, newRoot) : emptyMap(); - } - - function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) { - if (!node) { - if (value === NOT_SET) { - return node; - } - SetRef(didAlter); - SetRef(didChangeSize); - return new ValueNode(ownerID, keyHash, [key, value]); - } - return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter); - } - - function isLeafNode(node) { - return node.constructor === ValueNode || node.constructor === HashCollisionNode; - } - - function mergeIntoNode(node, ownerID, shift, keyHash, entry) { - if (node.keyHash === keyHash) { - return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]); - } - - var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK; - var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK; - - var newNode; - var nodes = idx1 === idx2 ? - [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] : - ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]); - - return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes); - } - - function createNodes(ownerID, entries, key, value) { - if (!ownerID) { - ownerID = new OwnerID(); - } - var node = new ValueNode(ownerID, hash(key), [key, value]); - for (var ii = 0; ii < entries.length; ii++) { - var entry = entries[ii]; - node = node.update(ownerID, 0, undefined, entry[0], entry[1]); - } - return node; - } - - function packNodes(ownerID, nodes, count, excluding) { - var bitmap = 0; - var packedII = 0; - var packedNodes = new Array(count); - for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) { - var node = nodes[ii]; - if (node !== undefined && ii !== excluding) { - bitmap |= bit; - packedNodes[packedII++] = node; - } - } - return new BitmapIndexedNode(ownerID, bitmap, packedNodes); - } - - function expandNodes(ownerID, nodes, bitmap, including, node) { - var count = 0; - var expandedNodes = new Array(SIZE); - for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) { - expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined; - } - expandedNodes[including] = node; - return new HashArrayMapNode(ownerID, count + 1, expandedNodes); - } - - function mergeIntoMapWith(map, merger, iterables) { - var iters = []; - for (var ii = 0; ii < iterables.length; ii++) { - var value = iterables[ii]; - var iter = KeyedIterable(value); - if (!isIterable(value)) { - iter = iter.map(function(v ) {return fromJS(v)}); - } - iters.push(iter); - } - return mergeIntoCollectionWith(map, merger, iters); - } - - function deepMerger(existing, value, key) { - return existing && existing.mergeDeep && isIterable(value) ? - existing.mergeDeep(value) : - is(existing, value) ? existing : value; - } - - function deepMergerWith(merger) { - return function(existing, value, key) { - if (existing && existing.mergeDeepWith && isIterable(value)) { - return existing.mergeDeepWith(merger, value); - } - var nextValue = merger(existing, value, key); - return is(existing, nextValue) ? existing : nextValue; - }; - } - - function mergeIntoCollectionWith(collection, merger, iters) { - iters = iters.filter(function(x ) {return x.size !== 0}); - if (iters.length === 0) { - return collection; - } - if (collection.size === 0 && !collection.__ownerID && iters.length === 1) { - return collection.constructor(iters[0]); - } - return collection.withMutations(function(collection ) { - var mergeIntoMap = merger ? - function(value, key) { - collection.update(key, NOT_SET, function(existing ) - {return existing === NOT_SET ? value : merger(existing, value, key)} - ); - } : - function(value, key) { - collection.set(key, value); - }; - for (var ii = 0; ii < iters.length; ii++) { - iters[ii].forEach(mergeIntoMap); - } - }); - } - - function updateInDeepMap(existing, keyPathIter, notSetValue, updater) { - var isNotSet = existing === NOT_SET; - var step = keyPathIter.next(); - if (step.done) { - var existingValue = isNotSet ? notSetValue : existing; - var newValue = updater(existingValue); - return newValue === existingValue ? existing : newValue; - } - invariant( - isNotSet || (existing && existing.set), - 'invalid keyPath' - ); - var key = step.value; - var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET); - var nextUpdated = updateInDeepMap( - nextExisting, - keyPathIter, - notSetValue, - updater - ); - return nextUpdated === nextExisting ? existing : - nextUpdated === NOT_SET ? existing.remove(key) : - (isNotSet ? emptyMap() : existing).set(key, nextUpdated); - } - - function popCount(x) { - x = x - ((x >> 1) & 0x55555555); - x = (x & 0x33333333) + ((x >> 2) & 0x33333333); - x = (x + (x >> 4)) & 0x0f0f0f0f; - x = x + (x >> 8); - x = x + (x >> 16); - return x & 0x7f; - } - - function setIn(array, idx, val, canEdit) { - var newArray = canEdit ? array : arrCopy(array); - newArray[idx] = val; - return newArray; - } - - function spliceIn(array, idx, val, canEdit) { - var newLen = array.length + 1; - if (canEdit && idx + 1 === newLen) { - array[idx] = val; - return array; - } - var newArray = new Array(newLen); - var after = 0; - for (var ii = 0; ii < newLen; ii++) { - if (ii === idx) { - newArray[ii] = val; - after = -1; - } else { - newArray[ii] = array[ii + after]; - } - } - return newArray; - } - - function spliceOut(array, idx, canEdit) { - var newLen = array.length - 1; - if (canEdit && idx === newLen) { - array.pop(); - return array; - } - var newArray = new Array(newLen); - var after = 0; - for (var ii = 0; ii < newLen; ii++) { - if (ii === idx) { - after = 1; - } - newArray[ii] = array[ii + after]; - } - return newArray; - } - - var MAX_ARRAY_MAP_SIZE = SIZE / 4; - var MAX_BITMAP_INDEXED_SIZE = SIZE / 2; - var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4; - - createClass(List, IndexedCollection); - - // @pragma Construction - - function List(value) { - var empty = emptyList(); - if (value === null || value === undefined) { - return empty; - } - if (isList(value)) { - return value; - } - var iter = IndexedIterable(value); - var size = iter.size; - if (size === 0) { - return empty; - } - assertNotInfinite(size); - if (size > 0 && size < SIZE) { - return makeList(0, size, SHIFT, null, new VNode(iter.toArray())); - } - return empty.withMutations(function(list ) { - list.setSize(size); - iter.forEach(function(v, i) {return list.set(i, v)}); - }); - } - - List.of = function(/*...values*/) { - return this(arguments); - }; - - List.prototype.toString = function() { - return this.__toString('List [', ']'); - }; - - // @pragma Access - - List.prototype.get = function(index, notSetValue) { - index = wrapIndex(this, index); - if (index >= 0 && index < this.size) { - index += this._origin; - var node = listNodeFor(this, index); - return node && node.array[index & MASK]; - } - return notSetValue; - }; - - // @pragma Modification - - List.prototype.set = function(index, value) { - return updateList(this, index, value); - }; - - List.prototype.remove = function(index) { - return !this.has(index) ? this : - index === 0 ? this.shift() : - index === this.size - 1 ? this.pop() : - this.splice(index, 1); - }; - - List.prototype.insert = function(index, value) { - return this.splice(index, 0, value); - }; - - List.prototype.clear = function() { - if (this.size === 0) { - return this; - } - if (this.__ownerID) { - this.size = this._origin = this._capacity = 0; - this._level = SHIFT; - this._root = this._tail = null; - this.__hash = undefined; - this.__altered = true; - return this; - } - return emptyList(); - }; - - List.prototype.push = function(/*...values*/) { - var values = arguments; - var oldSize = this.size; - return this.withMutations(function(list ) { - setListBounds(list, 0, oldSize + values.length); - for (var ii = 0; ii < values.length; ii++) { - list.set(oldSize + ii, values[ii]); - } - }); - }; - - List.prototype.pop = function() { - return setListBounds(this, 0, -1); - }; - - List.prototype.unshift = function(/*...values*/) { - var values = arguments; - return this.withMutations(function(list ) { - setListBounds(list, -values.length); - for (var ii = 0; ii < values.length; ii++) { - list.set(ii, values[ii]); - } - }); - }; - - List.prototype.shift = function() { - return setListBounds(this, 1); - }; - - // @pragma Composition - - List.prototype.merge = function(/*...iters*/) { - return mergeIntoListWith(this, undefined, arguments); - }; - - List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1); - return mergeIntoListWith(this, merger, iters); - }; - - List.prototype.mergeDeep = function(/*...iters*/) { - return mergeIntoListWith(this, deepMerger, arguments); - }; - - List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1); - return mergeIntoListWith(this, deepMergerWith(merger), iters); - }; - - List.prototype.setSize = function(size) { - return setListBounds(this, 0, size); - }; - - // @pragma Iteration - - List.prototype.slice = function(begin, end) { - var size = this.size; - if (wholeSlice(begin, end, size)) { - return this; - } - return setListBounds( - this, - resolveBegin(begin, size), - resolveEnd(end, size) - ); - }; - - List.prototype.__iterator = function(type, reverse) { - var index = 0; - var values = iterateList(this, reverse); - return new Iterator(function() { - var value = values(); - return value === DONE ? - iteratorDone() : - iteratorValue(type, index++, value); - }); - }; - - List.prototype.__iterate = function(fn, reverse) { - var index = 0; - var values = iterateList(this, reverse); - var value; - while ((value = values()) !== DONE) { - if (fn(value, index++, this) === false) { - break; - } - } - return index; - }; - - List.prototype.__ensureOwner = function(ownerID) { - if (ownerID === this.__ownerID) { - return this; - } - if (!ownerID) { - this.__ownerID = ownerID; - return this; - } - return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash); - }; - - - function isList(maybeList) { - return !!(maybeList && maybeList[IS_LIST_SENTINEL]); - } - - List.isList = isList; - - var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@'; - - var ListPrototype = List.prototype; - ListPrototype[IS_LIST_SENTINEL] = true; - ListPrototype[DELETE] = ListPrototype.remove; - ListPrototype.setIn = MapPrototype.setIn; - ListPrototype.deleteIn = - ListPrototype.removeIn = MapPrototype.removeIn; - ListPrototype.update = MapPrototype.update; - ListPrototype.updateIn = MapPrototype.updateIn; - ListPrototype.mergeIn = MapPrototype.mergeIn; - ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn; - ListPrototype.withMutations = MapPrototype.withMutations; - ListPrototype.asMutable = MapPrototype.asMutable; - ListPrototype.asImmutable = MapPrototype.asImmutable; - ListPrototype.wasAltered = MapPrototype.wasAltered; - - - - function VNode(array, ownerID) { - this.array = array; - this.ownerID = ownerID; - } - - // TODO: seems like these methods are very similar - - VNode.prototype.removeBefore = function(ownerID, level, index) { - if (index === level ? 1 << level : this.array.length === 0) { - return this; - } - var originIndex = (index >>> level) & MASK; - if (originIndex >= this.array.length) { - return new VNode([], ownerID); - } - var removingFirst = originIndex === 0; - var newChild; - if (level > 0) { - var oldChild = this.array[originIndex]; - newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index); - if (newChild === oldChild && removingFirst) { - return this; - } - } - if (removingFirst && !newChild) { - return this; - } - var editable = editableVNode(this, ownerID); - if (!removingFirst) { - for (var ii = 0; ii < originIndex; ii++) { - editable.array[ii] = undefined; - } - } - if (newChild) { - editable.array[originIndex] = newChild; - } - return editable; - }; - - VNode.prototype.removeAfter = function(ownerID, level, index) { - if (index === (level ? 1 << level : 0) || this.array.length === 0) { - return this; - } - var sizeIndex = ((index - 1) >>> level) & MASK; - if (sizeIndex >= this.array.length) { - return this; - } - - var newChild; - if (level > 0) { - var oldChild = this.array[sizeIndex]; - newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index); - if (newChild === oldChild && sizeIndex === this.array.length - 1) { - return this; - } - } - - var editable = editableVNode(this, ownerID); - editable.array.splice(sizeIndex + 1); - if (newChild) { - editable.array[sizeIndex] = newChild; - } - return editable; - }; - - - - var DONE = {}; - - function iterateList(list, reverse) { - var left = list._origin; - var right = list._capacity; - var tailPos = getTailOffset(right); - var tail = list._tail; - - return iterateNodeOrLeaf(list._root, list._level, 0); - - function iterateNodeOrLeaf(node, level, offset) { - return level === 0 ? - iterateLeaf(node, offset) : - iterateNode(node, level, offset); - } - - function iterateLeaf(node, offset) { - var array = offset === tailPos ? tail && tail.array : node && node.array; - var from = offset > left ? 0 : left - offset; - var to = right - offset; - if (to > SIZE) { - to = SIZE; - } - return function() { - if (from === to) { - return DONE; - } - var idx = reverse ? --to : from++; - return array && array[idx]; - }; - } - - function iterateNode(node, level, offset) { - var values; - var array = node && node.array; - var from = offset > left ? 0 : (left - offset) >> level; - var to = ((right - offset) >> level) + 1; - if (to > SIZE) { - to = SIZE; - } - return function() { - do { - if (values) { - var value = values(); - if (value !== DONE) { - return value; - } - values = null; - } - if (from === to) { - return DONE; - } - var idx = reverse ? --to : from++; - values = iterateNodeOrLeaf( - array && array[idx], level - SHIFT, offset + (idx << level) - ); - } while (true); - }; - } - } - - function makeList(origin, capacity, level, root, tail, ownerID, hash) { - var list = Object.create(ListPrototype); - list.size = capacity - origin; - list._origin = origin; - list._capacity = capacity; - list._level = level; - list._root = root; - list._tail = tail; - list.__ownerID = ownerID; - list.__hash = hash; - list.__altered = false; - return list; - } - - var EMPTY_LIST; - function emptyList() { - return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT)); - } - - function updateList(list, index, value) { - index = wrapIndex(list, index); - - if (index !== index) { - return list; - } - - if (index >= list.size || index < 0) { - return list.withMutations(function(list ) { - index < 0 ? - setListBounds(list, index).set(0, value) : - setListBounds(list, 0, index + 1).set(index, value); - }); - } - - index += list._origin; - - var newTail = list._tail; - var newRoot = list._root; - var didAlter = MakeRef(DID_ALTER); - if (index >= getTailOffset(list._capacity)) { - newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter); - } else { - newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter); - } - - if (!didAlter.value) { - return list; - } - - if (list.__ownerID) { - list._root = newRoot; - list._tail = newTail; - list.__hash = undefined; - list.__altered = true; - return list; - } - return makeList(list._origin, list._capacity, list._level, newRoot, newTail); - } - - function updateVNode(node, ownerID, level, index, value, didAlter) { - var idx = (index >>> level) & MASK; - var nodeHas = node && idx < node.array.length; - if (!nodeHas && value === undefined) { - return node; - } - - var newNode; - - if (level > 0) { - var lowerNode = node && node.array[idx]; - var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter); - if (newLowerNode === lowerNode) { - return node; - } - newNode = editableVNode(node, ownerID); - newNode.array[idx] = newLowerNode; - return newNode; - } - - if (nodeHas && node.array[idx] === value) { - return node; - } - - SetRef(didAlter); - - newNode = editableVNode(node, ownerID); - if (value === undefined && idx === newNode.array.length - 1) { - newNode.array.pop(); - } else { - newNode.array[idx] = value; - } - return newNode; - } - - function editableVNode(node, ownerID) { - if (ownerID && node && ownerID === node.ownerID) { - return node; - } - return new VNode(node ? node.array.slice() : [], ownerID); - } - - function listNodeFor(list, rawIndex) { - if (rawIndex >= getTailOffset(list._capacity)) { - return list._tail; - } - if (rawIndex < 1 << (list._level + SHIFT)) { - var node = list._root; - var level = list._level; - while (node && level > 0) { - node = node.array[(rawIndex >>> level) & MASK]; - level -= SHIFT; - } - return node; - } - } - - function setListBounds(list, begin, end) { - // Sanitize begin & end using this shorthand for ToInt32(argument) - // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32 - if (begin !== undefined) { - begin = begin | 0; - } - if (end !== undefined) { - end = end | 0; - } - var owner = list.__ownerID || new OwnerID(); - var oldOrigin = list._origin; - var oldCapacity = list._capacity; - var newOrigin = oldOrigin + begin; - var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end; - if (newOrigin === oldOrigin && newCapacity === oldCapacity) { - return list; - } - - // If it's going to end after it starts, it's empty. - if (newOrigin >= newCapacity) { - return list.clear(); - } - - var newLevel = list._level; - var newRoot = list._root; - - // New origin might need creating a higher root. - var offsetShift = 0; - while (newOrigin + offsetShift < 0) { - newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner); - newLevel += SHIFT; - offsetShift += 1 << newLevel; - } - if (offsetShift) { - newOrigin += offsetShift; - oldOrigin += offsetShift; - newCapacity += offsetShift; - oldCapacity += offsetShift; - } - - var oldTailOffset = getTailOffset(oldCapacity); - var newTailOffset = getTailOffset(newCapacity); - - // New size might need creating a higher root. - while (newTailOffset >= 1 << (newLevel + SHIFT)) { - newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner); - newLevel += SHIFT; - } - - // Locate or create the new tail. - var oldTail = list._tail; - var newTail = newTailOffset < oldTailOffset ? - listNodeFor(list, newCapacity - 1) : - newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail; - - // Merge Tail into tree. - if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) { - newRoot = editableVNode(newRoot, owner); - var node = newRoot; - for (var level = newLevel; level > SHIFT; level -= SHIFT) { - var idx = (oldTailOffset >>> level) & MASK; - node = node.array[idx] = editableVNode(node.array[idx], owner); - } - node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail; - } - - // If the size has been reduced, there's a chance the tail needs to be trimmed. - if (newCapacity < oldCapacity) { - newTail = newTail && newTail.removeAfter(owner, 0, newCapacity); - } - - // If the new origin is within the tail, then we do not need a root. - if (newOrigin >= newTailOffset) { - newOrigin -= newTailOffset; - newCapacity -= newTailOffset; - newLevel = SHIFT; - newRoot = null; - newTail = newTail && newTail.removeBefore(owner, 0, newOrigin); - - // Otherwise, if the root has been trimmed, garbage collect. - } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) { - offsetShift = 0; - - // Identify the new top root node of the subtree of the old root. - while (newRoot) { - var beginIndex = (newOrigin >>> newLevel) & MASK; - if (beginIndex !== (newTailOffset >>> newLevel) & MASK) { - break; - } - if (beginIndex) { - offsetShift += (1 << newLevel) * beginIndex; - } - newLevel -= SHIFT; - newRoot = newRoot.array[beginIndex]; - } - - // Trim the new sides of the new root. - if (newRoot && newOrigin > oldOrigin) { - newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift); - } - if (newRoot && newTailOffset < oldTailOffset) { - newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift); - } - if (offsetShift) { - newOrigin -= offsetShift; - newCapacity -= offsetShift; - } - } - - if (list.__ownerID) { - list.size = newCapacity - newOrigin; - list._origin = newOrigin; - list._capacity = newCapacity; - list._level = newLevel; - list._root = newRoot; - list._tail = newTail; - list.__hash = undefined; - list.__altered = true; - return list; - } - return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail); - } - - function mergeIntoListWith(list, merger, iterables) { - var iters = []; - var maxSize = 0; - for (var ii = 0; ii < iterables.length; ii++) { - var value = iterables[ii]; - var iter = IndexedIterable(value); - if (iter.size > maxSize) { - maxSize = iter.size; - } - if (!isIterable(value)) { - iter = iter.map(function(v ) {return fromJS(v)}); - } - iters.push(iter); - } - if (maxSize > list.size) { - list = list.setSize(maxSize); - } - return mergeIntoCollectionWith(list, merger, iters); - } - - function getTailOffset(size) { - return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT); - } - - createClass(OrderedMap, Map); - - // @pragma Construction - - function OrderedMap(value) { - return value === null || value === undefined ? emptyOrderedMap() : - isOrderedMap(value) ? value : - emptyOrderedMap().withMutations(function(map ) { - var iter = KeyedIterable(value); - assertNotInfinite(iter.size); - iter.forEach(function(v, k) {return map.set(k, v)}); - }); - } - - OrderedMap.of = function(/*...values*/) { - return this(arguments); - }; - - OrderedMap.prototype.toString = function() { - return this.__toString('OrderedMap {', '}'); - }; - - // @pragma Access - - OrderedMap.prototype.get = function(k, notSetValue) { - var index = this._map.get(k); - return index !== undefined ? this._list.get(index)[1] : notSetValue; - }; - - // @pragma Modification - - OrderedMap.prototype.clear = function() { - if (this.size === 0) { - return this; - } - if (this.__ownerID) { - this.size = 0; - this._map.clear(); - this._list.clear(); - return this; - } - return emptyOrderedMap(); - }; - - OrderedMap.prototype.set = function(k, v) { - return updateOrderedMap(this, k, v); - }; - - OrderedMap.prototype.remove = function(k) { - return updateOrderedMap(this, k, NOT_SET); - }; - - OrderedMap.prototype.wasAltered = function() { - return this._map.wasAltered() || this._list.wasAltered(); - }; - - OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this; - return this._list.__iterate( - function(entry ) {return entry && fn(entry[1], entry[0], this$0)}, - reverse - ); - }; - - OrderedMap.prototype.__iterator = function(type, reverse) { - return this._list.fromEntrySeq().__iterator(type, reverse); - }; - - OrderedMap.prototype.__ensureOwner = function(ownerID) { - if (ownerID === this.__ownerID) { - return this; - } - var newMap = this._map.__ensureOwner(ownerID); - var newList = this._list.__ensureOwner(ownerID); - if (!ownerID) { - this.__ownerID = ownerID; - this._map = newMap; - this._list = newList; - return this; - } - return makeOrderedMap(newMap, newList, ownerID, this.__hash); - }; - - - function isOrderedMap(maybeOrderedMap) { - return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap); - } - - OrderedMap.isOrderedMap = isOrderedMap; - - OrderedMap.prototype[IS_ORDERED_SENTINEL] = true; - OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove; - - - - function makeOrderedMap(map, list, ownerID, hash) { - var omap = Object.create(OrderedMap.prototype); - omap.size = map ? map.size : 0; - omap._map = map; - omap._list = list; - omap.__ownerID = ownerID; - omap.__hash = hash; - return omap; - } - - var EMPTY_ORDERED_MAP; - function emptyOrderedMap() { - return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList())); - } - - function updateOrderedMap(omap, k, v) { - var map = omap._map; - var list = omap._list; - var i = map.get(k); - var has = i !== undefined; - var newMap; - var newList; - if (v === NOT_SET) { // removed - if (!has) { - return omap; - } - if (list.size >= SIZE && list.size >= map.size * 2) { - newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx}); - newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap(); - if (omap.__ownerID) { - newMap.__ownerID = newList.__ownerID = omap.__ownerID; - } - } else { - newMap = map.remove(k); - newList = i === list.size - 1 ? list.pop() : list.set(i, undefined); - } - } else { - if (has) { - if (v === list.get(i)[1]) { - return omap; - } - newMap = map; - newList = list.set(i, [k, v]); - } else { - newMap = map.set(k, list.size); - newList = list.set(list.size, [k, v]); - } - } - if (omap.__ownerID) { - omap.size = newMap.size; - omap._map = newMap; - omap._list = newList; - omap.__hash = undefined; - return omap; - } - return makeOrderedMap(newMap, newList); - } - - createClass(ToKeyedSequence, KeyedSeq); - function ToKeyedSequence(indexed, useKeys) { - this._iter = indexed; - this._useKeys = useKeys; - this.size = indexed.size; - } - - ToKeyedSequence.prototype.get = function(key, notSetValue) { - return this._iter.get(key, notSetValue); - }; - - ToKeyedSequence.prototype.has = function(key) { - return this._iter.has(key); - }; - - ToKeyedSequence.prototype.valueSeq = function() { - return this._iter.valueSeq(); - }; - - ToKeyedSequence.prototype.reverse = function() {var this$0 = this; - var reversedSequence = reverseFactory(this, true); - if (!this._useKeys) { - reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()}; - } - return reversedSequence; - }; - - ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this; - var mappedSequence = mapFactory(this, mapper, context); - if (!this._useKeys) { - mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)}; - } - return mappedSequence; - }; - - ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this; - var ii; - return this._iter.__iterate( - this._useKeys ? - function(v, k) {return fn(v, k, this$0)} : - ((ii = reverse ? resolveSize(this) : 0), - function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}), - reverse - ); - }; - - ToKeyedSequence.prototype.__iterator = function(type, reverse) { - if (this._useKeys) { - return this._iter.__iterator(type, reverse); - } - var iterator = this._iter.__iterator(ITERATE_VALUES, reverse); - var ii = reverse ? resolveSize(this) : 0; - return new Iterator(function() { - var step = iterator.next(); - return step.done ? step : - iteratorValue(type, reverse ? --ii : ii++, step.value, step); - }); - }; - - ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true; - - - createClass(ToIndexedSequence, IndexedSeq); - function ToIndexedSequence(iter) { - this._iter = iter; - this.size = iter.size; - } - - ToIndexedSequence.prototype.includes = function(value) { - return this._iter.includes(value); - }; - - ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this; - var iterations = 0; - return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse); - }; - - ToIndexedSequence.prototype.__iterator = function(type, reverse) { - var iterator = this._iter.__iterator(ITERATE_VALUES, reverse); - var iterations = 0; - return new Iterator(function() { - var step = iterator.next(); - return step.done ? step : - iteratorValue(type, iterations++, step.value, step) - }); - }; - - - - createClass(ToSetSequence, SetSeq); - function ToSetSequence(iter) { - this._iter = iter; - this.size = iter.size; - } - - ToSetSequence.prototype.has = function(key) { - return this._iter.includes(key); - }; - - ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this; - return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse); - }; - - ToSetSequence.prototype.__iterator = function(type, reverse) { - var iterator = this._iter.__iterator(ITERATE_VALUES, reverse); - return new Iterator(function() { - var step = iterator.next(); - return step.done ? step : - iteratorValue(type, step.value, step.value, step); - }); - }; - - - - createClass(FromEntriesSequence, KeyedSeq); - function FromEntriesSequence(entries) { - this._iter = entries; - this.size = entries.size; - } - - FromEntriesSequence.prototype.entrySeq = function() { - return this._iter.toSeq(); - }; - - FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this; - return this._iter.__iterate(function(entry ) { - // Check if entry exists first so array access doesn't throw for holes - // in the parent iteration. - if (entry) { - validateEntry(entry); - var indexedIterable = isIterable(entry); - return fn( - indexedIterable ? entry.get(1) : entry[1], - indexedIterable ? entry.get(0) : entry[0], - this$0 - ); - } - }, reverse); - }; - - FromEntriesSequence.prototype.__iterator = function(type, reverse) { - var iterator = this._iter.__iterator(ITERATE_VALUES, reverse); - return new Iterator(function() { - while (true) { - var step = iterator.next(); - if (step.done) { - return step; - } - var entry = step.value; - // Check if entry exists first so array access doesn't throw for holes - // in the parent iteration. - if (entry) { - validateEntry(entry); - var indexedIterable = isIterable(entry); - return iteratorValue( - type, - indexedIterable ? entry.get(0) : entry[0], - indexedIterable ? entry.get(1) : entry[1], - step - ); - } - } - }); - }; - - - ToIndexedSequence.prototype.cacheResult = - ToKeyedSequence.prototype.cacheResult = - ToSetSequence.prototype.cacheResult = - FromEntriesSequence.prototype.cacheResult = - cacheResultThrough; - - - function flipFactory(iterable) { - var flipSequence = makeSequence(iterable); - flipSequence._iter = iterable; - flipSequence.size = iterable.size; - flipSequence.flip = function() {return iterable}; - flipSequence.reverse = function () { - var reversedSequence = iterable.reverse.apply(this); // super.reverse() - reversedSequence.flip = function() {return iterable.reverse()}; - return reversedSequence; - }; - flipSequence.has = function(key ) {return iterable.includes(key)}; - flipSequence.includes = function(key ) {return iterable.has(key)}; - flipSequence.cacheResult = cacheResultThrough; - flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this; - return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse); - }; - flipSequence.__iteratorUncached = function(type, reverse) { - if (type === ITERATE_ENTRIES) { - var iterator = iterable.__iterator(type, reverse); - return new Iterator(function() { - var step = iterator.next(); - if (!step.done) { - var k = step.value[0]; - step.value[0] = step.value[1]; - step.value[1] = k; - } - return step; - }); - } - return iterable.__iterator( - type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES, - reverse - ); - }; - return flipSequence; - } - - - function mapFactory(iterable, mapper, context) { - var mappedSequence = makeSequence(iterable); - mappedSequence.size = iterable.size; - mappedSequence.has = function(key ) {return iterable.has(key)}; - mappedSequence.get = function(key, notSetValue) { - var v = iterable.get(key, NOT_SET); - return v === NOT_SET ? - notSetValue : - mapper.call(context, v, key, iterable); - }; - mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this; - return iterable.__iterate( - function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false}, - reverse - ); - }; - mappedSequence.__iteratorUncached = function (type, reverse) { - var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse); - return new Iterator(function() { - var step = iterator.next(); - if (step.done) { - return step; - } - var entry = step.value; - var key = entry[0]; - return iteratorValue( - type, - key, - mapper.call(context, entry[1], key, iterable), - step - ); - }); - }; - return mappedSequence; - } - - - function reverseFactory(iterable, useKeys) { - var reversedSequence = makeSequence(iterable); - reversedSequence._iter = iterable; - reversedSequence.size = iterable.size; - reversedSequence.reverse = function() {return iterable}; - if (iterable.flip) { - reversedSequence.flip = function () { - var flipSequence = flipFactory(iterable); - flipSequence.reverse = function() {return iterable.flip()}; - return flipSequence; - }; - } - reversedSequence.get = function(key, notSetValue) - {return iterable.get(useKeys ? key : -1 - key, notSetValue)}; - reversedSequence.has = function(key ) - {return iterable.has(useKeys ? key : -1 - key)}; - reversedSequence.includes = function(value ) {return iterable.includes(value)}; - reversedSequence.cacheResult = cacheResultThrough; - reversedSequence.__iterate = function (fn, reverse) {var this$0 = this; - return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse); - }; - reversedSequence.__iterator = - function(type, reverse) {return iterable.__iterator(type, !reverse)}; - return reversedSequence; - } - - - function filterFactory(iterable, predicate, context, useKeys) { - var filterSequence = makeSequence(iterable); - if (useKeys) { - filterSequence.has = function(key ) { - var v = iterable.get(key, NOT_SET); - return v !== NOT_SET && !!predicate.call(context, v, key, iterable); - }; - filterSequence.get = function(key, notSetValue) { - var v = iterable.get(key, NOT_SET); - return v !== NOT_SET && predicate.call(context, v, key, iterable) ? - v : notSetValue; - }; - } - filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this; - var iterations = 0; - iterable.__iterate(function(v, k, c) { - if (predicate.call(context, v, k, c)) { - iterations++; - return fn(v, useKeys ? k : iterations - 1, this$0); - } - }, reverse); - return iterations; - }; - filterSequence.__iteratorUncached = function (type, reverse) { - var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse); - var iterations = 0; - return new Iterator(function() { - while (true) { - var step = iterator.next(); - if (step.done) { - return step; - } - var entry = step.value; - var key = entry[0]; - var value = entry[1]; - if (predicate.call(context, value, key, iterable)) { - return iteratorValue(type, useKeys ? key : iterations++, value, step); - } - } - }); - }; - return filterSequence; - } - - - function countByFactory(iterable, grouper, context) { - var groups = Map().asMutable(); - iterable.__iterate(function(v, k) { - groups.update( - grouper.call(context, v, k, iterable), - 0, - function(a ) {return a + 1} - ); - }); - return groups.asImmutable(); - } - - - function groupByFactory(iterable, grouper, context) { - var isKeyedIter = isKeyed(iterable); - var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable(); - iterable.__iterate(function(v, k) { - groups.update( - grouper.call(context, v, k, iterable), - function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)} - ); - }); - var coerce = iterableClass(iterable); - return groups.map(function(arr ) {return reify(iterable, coerce(arr))}); - } - - - function sliceFactory(iterable, begin, end, useKeys) { - var originalSize = iterable.size; - - // Sanitize begin & end using this shorthand for ToInt32(argument) - // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32 - if (begin !== undefined) { - begin = begin | 0; - } - if (end !== undefined) { - if (end === Infinity) { - end = originalSize; - } else { - end = end | 0; - } - } - - if (wholeSlice(begin, end, originalSize)) { - return iterable; - } - - var resolvedBegin = resolveBegin(begin, originalSize); - var resolvedEnd = resolveEnd(end, originalSize); - - // begin or end will be NaN if they were provided as negative numbers and - // this iterable's size is unknown. In that case, cache first so there is - // a known size and these do not resolve to NaN. - if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) { - return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys); - } - - // Note: resolvedEnd is undefined when the original sequence's length is - // unknown and this slice did not supply an end and should contain all - // elements after resolvedBegin. - // In that case, resolvedSize will be NaN and sliceSize will remain undefined. - var resolvedSize = resolvedEnd - resolvedBegin; - var sliceSize; - if (resolvedSize === resolvedSize) { - sliceSize = resolvedSize < 0 ? 0 : resolvedSize; - } - - var sliceSeq = makeSequence(iterable); - - // If iterable.size is undefined, the size of the realized sliceSeq is - // unknown at this point unless the number of items to slice is 0 - sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined; - - if (!useKeys && isSeq(iterable) && sliceSize >= 0) { - sliceSeq.get = function (index, notSetValue) { - index = wrapIndex(this, index); - return index >= 0 && index < sliceSize ? - iterable.get(index + resolvedBegin, notSetValue) : - notSetValue; - }; - } - - sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this; - if (sliceSize === 0) { - return 0; - } - if (reverse) { - return this.cacheResult().__iterate(fn, reverse); - } - var skipped = 0; - var isSkipping = true; - var iterations = 0; - iterable.__iterate(function(v, k) { - if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) { - iterations++; - return fn(v, useKeys ? k : iterations - 1, this$0) !== false && - iterations !== sliceSize; - } - }); - return iterations; - }; - - sliceSeq.__iteratorUncached = function(type, reverse) { - if (sliceSize !== 0 && reverse) { - return this.cacheResult().__iterator(type, reverse); - } - // Don't bother instantiating parent iterator if taking 0. - var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse); - var skipped = 0; - var iterations = 0; - return new Iterator(function() { - while (skipped++ < resolvedBegin) { - iterator.next(); - } - if (++iterations > sliceSize) { - return iteratorDone(); - } - var step = iterator.next(); - if (useKeys || type === ITERATE_VALUES) { - return step; - } else if (type === ITERATE_KEYS) { - return iteratorValue(type, iterations - 1, undefined, step); - } else { - return iteratorValue(type, iterations - 1, step.value[1], step); - } - }); - }; - - return sliceSeq; - } - - - function takeWhileFactory(iterable, predicate, context) { - var takeSequence = makeSequence(iterable); - takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this; - if (reverse) { - return this.cacheResult().__iterate(fn, reverse); - } - var iterations = 0; - iterable.__iterate(function(v, k, c) - {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)} - ); - return iterations; - }; - takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this; - if (reverse) { - return this.cacheResult().__iterator(type, reverse); - } - var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse); - var iterating = true; - return new Iterator(function() { - if (!iterating) { - return iteratorDone(); - } - var step = iterator.next(); - if (step.done) { - return step; - } - var entry = step.value; - var k = entry[0]; - var v = entry[1]; - if (!predicate.call(context, v, k, this$0)) { - iterating = false; - return iteratorDone(); - } - return type === ITERATE_ENTRIES ? step : - iteratorValue(type, k, v, step); - }); - }; - return takeSequence; - } - - - function skipWhileFactory(iterable, predicate, context, useKeys) { - var skipSequence = makeSequence(iterable); - skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this; - if (reverse) { - return this.cacheResult().__iterate(fn, reverse); - } - var isSkipping = true; - var iterations = 0; - iterable.__iterate(function(v, k, c) { - if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) { - iterations++; - return fn(v, useKeys ? k : iterations - 1, this$0); - } - }); - return iterations; - }; - skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this; - if (reverse) { - return this.cacheResult().__iterator(type, reverse); - } - var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse); - var skipping = true; - var iterations = 0; - return new Iterator(function() { - var step, k, v; - do { - step = iterator.next(); - if (step.done) { - if (useKeys || type === ITERATE_VALUES) { - return step; - } else if (type === ITERATE_KEYS) { - return iteratorValue(type, iterations++, undefined, step); - } else { - return iteratorValue(type, iterations++, step.value[1], step); - } - } - var entry = step.value; - k = entry[0]; - v = entry[1]; - skipping && (skipping = predicate.call(context, v, k, this$0)); - } while (skipping); - return type === ITERATE_ENTRIES ? step : - iteratorValue(type, k, v, step); - }); - }; - return skipSequence; - } - - - function concatFactory(iterable, values) { - var isKeyedIterable = isKeyed(iterable); - var iters = [iterable].concat(values).map(function(v ) { - if (!isIterable(v)) { - v = isKeyedIterable ? - keyedSeqFromValue(v) : - indexedSeqFromValue(Array.isArray(v) ? v : [v]); - } else if (isKeyedIterable) { - v = KeyedIterable(v); - } - return v; - }).filter(function(v ) {return v.size !== 0}); - - if (iters.length === 0) { - return iterable; - } - - if (iters.length === 1) { - var singleton = iters[0]; - if (singleton === iterable || - isKeyedIterable && isKeyed(singleton) || - isIndexed(iterable) && isIndexed(singleton)) { - return singleton; - } - } - - var concatSeq = new ArraySeq(iters); - if (isKeyedIterable) { - concatSeq = concatSeq.toKeyedSeq(); - } else if (!isIndexed(iterable)) { - concatSeq = concatSeq.toSetSeq(); - } - concatSeq = concatSeq.flatten(true); - concatSeq.size = iters.reduce( - function(sum, seq) { - if (sum !== undefined) { - var size = seq.size; - if (size !== undefined) { - return sum + size; - } - } - }, - 0 - ); - return concatSeq; - } - - - function flattenFactory(iterable, depth, useKeys) { - var flatSequence = makeSequence(iterable); - flatSequence.__iterateUncached = function(fn, reverse) { - var iterations = 0; - var stopped = false; - function flatDeep(iter, currentDepth) {var this$0 = this; - iter.__iterate(function(v, k) { - if ((!depth || currentDepth < depth) && isIterable(v)) { - flatDeep(v, currentDepth + 1); - } else if (fn(v, useKeys ? k : iterations++, this$0) === false) { - stopped = true; - } - return !stopped; - }, reverse); - } - flatDeep(iterable, 0); - return iterations; - }; - flatSequence.__iteratorUncached = function(type, reverse) { - var iterator = iterable.__iterator(type, reverse); - var stack = []; - var iterations = 0; - return new Iterator(function() { - while (iterator) { - var step = iterator.next(); - if (step.done !== false) { - iterator = stack.pop(); - continue; - } - var v = step.value; - if (type === ITERATE_ENTRIES) { - v = v[1]; - } - if ((!depth || stack.length < depth) && isIterable(v)) { - stack.push(iterator); - iterator = v.__iterator(type, reverse); - } else { - return useKeys ? step : iteratorValue(type, iterations++, v, step); - } - } - return iteratorDone(); - }); - }; - return flatSequence; - } - - - function flatMapFactory(iterable, mapper, context) { - var coerce = iterableClass(iterable); - return iterable.toSeq().map( - function(v, k) {return coerce(mapper.call(context, v, k, iterable))} - ).flatten(true); - } - - - function interposeFactory(iterable, separator) { - var interposedSequence = makeSequence(iterable); - interposedSequence.size = iterable.size && iterable.size * 2 -1; - interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this; - var iterations = 0; - iterable.__iterate(function(v, k) - {return (!iterations || fn(separator, iterations++, this$0) !== false) && - fn(v, iterations++, this$0) !== false}, - reverse - ); - return iterations; - }; - interposedSequence.__iteratorUncached = function(type, reverse) { - var iterator = iterable.__iterator(ITERATE_VALUES, reverse); - var iterations = 0; - var step; - return new Iterator(function() { - if (!step || iterations % 2) { - step = iterator.next(); - if (step.done) { - return step; - } - } - return iterations % 2 ? - iteratorValue(type, iterations++, separator) : - iteratorValue(type, iterations++, step.value, step); - }); - }; - return interposedSequence; - } - - - function sortFactory(iterable, comparator, mapper) { - if (!comparator) { - comparator = defaultComparator; - } - var isKeyedIterable = isKeyed(iterable); - var index = 0; - var entries = iterable.toSeq().map( - function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]} - ).toArray(); - entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach( - isKeyedIterable ? - function(v, i) { entries[i].length = 2; } : - function(v, i) { entries[i] = v[1]; } - ); - return isKeyedIterable ? KeyedSeq(entries) : - isIndexed(iterable) ? IndexedSeq(entries) : - SetSeq(entries); - } - - - function maxFactory(iterable, comparator, mapper) { - if (!comparator) { - comparator = defaultComparator; - } - if (mapper) { - var entry = iterable.toSeq() - .map(function(v, k) {return [v, mapper(v, k, iterable)]}) - .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a}); - return entry && entry[0]; - } else { - return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a}); - } - } - - function maxCompare(comparator, a, b) { - var comp = comparator(b, a); - // b is considered the new max if the comparator declares them equal, but - // they are not equal and b is in fact a nullish value. - return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0; - } - - - function zipWithFactory(keyIter, zipper, iters) { - var zipSequence = makeSequence(keyIter); - zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min(); - // Note: this a generic base implementation of __iterate in terms of - // __iterator which may be more generically useful in the future. - zipSequence.__iterate = function(fn, reverse) { - /* generic: - var iterator = this.__iterator(ITERATE_ENTRIES, reverse); - var step; - var iterations = 0; - while (!(step = iterator.next()).done) { - iterations++; - if (fn(step.value[1], step.value[0], this) === false) { - break; - } - } - return iterations; - */ - // indexed: - var iterator = this.__iterator(ITERATE_VALUES, reverse); - var step; - var iterations = 0; - while (!(step = iterator.next()).done) { - if (fn(step.value, iterations++, this) === false) { - break; - } - } - return iterations; - }; - zipSequence.__iteratorUncached = function(type, reverse) { - var iterators = iters.map(function(i ) - {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))} - ); - var iterations = 0; - var isDone = false; - return new Iterator(function() { - var steps; - if (!isDone) { - steps = iterators.map(function(i ) {return i.next()}); - isDone = steps.some(function(s ) {return s.done}); - } - if (isDone) { - return iteratorDone(); - } - return iteratorValue( - type, - iterations++, - zipper.apply(null, steps.map(function(s ) {return s.value})) - ); - }); - }; - return zipSequence - } - - - // #pragma Helper Functions - - function reify(iter, seq) { - return isSeq(iter) ? seq : iter.constructor(seq); - } - - function validateEntry(entry) { - if (entry !== Object(entry)) { - throw new TypeError('Expected [K, V] tuple: ' + entry); - } - } - - function resolveSize(iter) { - assertNotInfinite(iter.size); - return ensureSize(iter); - } - - function iterableClass(iterable) { - return isKeyed(iterable) ? KeyedIterable : - isIndexed(iterable) ? IndexedIterable : - SetIterable; - } - - function makeSequence(iterable) { - return Object.create( - ( - isKeyed(iterable) ? KeyedSeq : - isIndexed(iterable) ? IndexedSeq : - SetSeq - ).prototype - ); - } - - function cacheResultThrough() { - if (this._iter.cacheResult) { - this._iter.cacheResult(); - this.size = this._iter.size; - return this; - } else { - return Seq.prototype.cacheResult.call(this); - } - } - - function defaultComparator(a, b) { - return a > b ? 1 : a < b ? -1 : 0; - } - - function forceIterator(keyPath) { - var iter = getIterator(keyPath); - if (!iter) { - // Array might not be iterable in this environment, so we need a fallback - // to our wrapped type. - if (!isArrayLike(keyPath)) { - throw new TypeError('Expected iterable or array-like: ' + keyPath); - } - iter = getIterator(Iterable(keyPath)); - } - return iter; - } - - createClass(Record, KeyedCollection); - - function Record(defaultValues, name) { - var hasInitialized; - - var RecordType = function Record(values) { - if (values instanceof RecordType) { - return values; - } - if (!(this instanceof RecordType)) { - return new RecordType(values); - } - if (!hasInitialized) { - hasInitialized = true; - var keys = Object.keys(defaultValues); - setProps(RecordTypePrototype, keys); - RecordTypePrototype.size = keys.length; - RecordTypePrototype._name = name; - RecordTypePrototype._keys = keys; - RecordTypePrototype._defaultValues = defaultValues; - } - this._map = Map(values); - }; - - var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype); - RecordTypePrototype.constructor = RecordType; - - return RecordType; - } - - Record.prototype.toString = function() { - return this.__toString(recordName(this) + ' {', '}'); - }; - - // @pragma Access - - Record.prototype.has = function(k) { - return this._defaultValues.hasOwnProperty(k); - }; - - Record.prototype.get = function(k, notSetValue) { - if (!this.has(k)) { - return notSetValue; - } - var defaultVal = this._defaultValues[k]; - return this._map ? this._map.get(k, defaultVal) : defaultVal; - }; - - // @pragma Modification - - Record.prototype.clear = function() { - if (this.__ownerID) { - this._map && this._map.clear(); - return this; - } - var RecordType = this.constructor; - return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap())); - }; - - Record.prototype.set = function(k, v) { - if (!this.has(k)) { - throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this)); - } - if (this._map && !this._map.has(k)) { - var defaultVal = this._defaultValues[k]; - if (v === defaultVal) { - return this; - } - } - var newMap = this._map && this._map.set(k, v); - if (this.__ownerID || newMap === this._map) { - return this; - } - return makeRecord(this, newMap); - }; - - Record.prototype.remove = function(k) { - if (!this.has(k)) { - return this; - } - var newMap = this._map && this._map.remove(k); - if (this.__ownerID || newMap === this._map) { - return this; - } - return makeRecord(this, newMap); - }; - - Record.prototype.wasAltered = function() { - return this._map.wasAltered(); - }; - - Record.prototype.__iterator = function(type, reverse) {var this$0 = this; - return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse); - }; - - Record.prototype.__iterate = function(fn, reverse) {var this$0 = this; - return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse); - }; - - Record.prototype.__ensureOwner = function(ownerID) { - if (ownerID === this.__ownerID) { - return this; - } - var newMap = this._map && this._map.__ensureOwner(ownerID); - if (!ownerID) { - this.__ownerID = ownerID; - this._map = newMap; - return this; - } - return makeRecord(this, newMap, ownerID); - }; - - - var RecordPrototype = Record.prototype; - RecordPrototype[DELETE] = RecordPrototype.remove; - RecordPrototype.deleteIn = - RecordPrototype.removeIn = MapPrototype.removeIn; - RecordPrototype.merge = MapPrototype.merge; - RecordPrototype.mergeWith = MapPrototype.mergeWith; - RecordPrototype.mergeIn = MapPrototype.mergeIn; - RecordPrototype.mergeDeep = MapPrototype.mergeDeep; - RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith; - RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn; - RecordPrototype.setIn = MapPrototype.setIn; - RecordPrototype.update = MapPrototype.update; - RecordPrototype.updateIn = MapPrototype.updateIn; - RecordPrototype.withMutations = MapPrototype.withMutations; - RecordPrototype.asMutable = MapPrototype.asMutable; - RecordPrototype.asImmutable = MapPrototype.asImmutable; - - - function makeRecord(likeRecord, map, ownerID) { - var record = Object.create(Object.getPrototypeOf(likeRecord)); - record._map = map; - record.__ownerID = ownerID; - return record; - } - - function recordName(record) { - return record._name || record.constructor.name || 'Record'; - } - - function setProps(prototype, names) { - try { - names.forEach(setProp.bind(undefined, prototype)); - } catch (error) { - // Object.defineProperty failed. Probably IE8. - } - } - - function setProp(prototype, name) { - Object.defineProperty(prototype, name, { - get: function() { - return this.get(name); - }, - set: function(value) { - invariant(this.__ownerID, 'Cannot set on an immutable record.'); - this.set(name, value); - } - }); - } - - createClass(Set, SetCollection); - - // @pragma Construction - - function Set(value) { - return value === null || value === undefined ? emptySet() : - isSet(value) && !isOrdered(value) ? value : - emptySet().withMutations(function(set ) { - var iter = SetIterable(value); - assertNotInfinite(iter.size); - iter.forEach(function(v ) {return set.add(v)}); - }); - } - - Set.of = function(/*...values*/) { - return this(arguments); - }; - - Set.fromKeys = function(value) { - return this(KeyedIterable(value).keySeq()); - }; - - Set.prototype.toString = function() { - return this.__toString('Set {', '}'); - }; - - // @pragma Access - - Set.prototype.has = function(value) { - return this._map.has(value); - }; - - // @pragma Modification - - Set.prototype.add = function(value) { - return updateSet(this, this._map.set(value, true)); - }; - - Set.prototype.remove = function(value) { - return updateSet(this, this._map.remove(value)); - }; - - Set.prototype.clear = function() { - return updateSet(this, this._map.clear()); - }; - - // @pragma Composition - - Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0); - iters = iters.filter(function(x ) {return x.size !== 0}); - if (iters.length === 0) { - return this; - } - if (this.size === 0 && !this.__ownerID && iters.length === 1) { - return this.constructor(iters[0]); - } - return this.withMutations(function(set ) { - for (var ii = 0; ii < iters.length; ii++) { - SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)}); - } - }); - }; - - Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0); - if (iters.length === 0) { - return this; - } - iters = iters.map(function(iter ) {return SetIterable(iter)}); - var originalSet = this; - return this.withMutations(function(set ) { - originalSet.forEach(function(value ) { - if (!iters.every(function(iter ) {return iter.includes(value)})) { - set.remove(value); - } - }); - }); - }; - - Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0); - if (iters.length === 0) { - return this; - } - iters = iters.map(function(iter ) {return SetIterable(iter)}); - var originalSet = this; - return this.withMutations(function(set ) { - originalSet.forEach(function(value ) { - if (iters.some(function(iter ) {return iter.includes(value)})) { - set.remove(value); - } - }); - }); - }; - - Set.prototype.merge = function() { - return this.union.apply(this, arguments); - }; - - Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1); - return this.union.apply(this, iters); - }; - - Set.prototype.sort = function(comparator) { - // Late binding - return OrderedSet(sortFactory(this, comparator)); - }; - - Set.prototype.sortBy = function(mapper, comparator) { - // Late binding - return OrderedSet(sortFactory(this, comparator, mapper)); - }; - - Set.prototype.wasAltered = function() { - return this._map.wasAltered(); - }; - - Set.prototype.__iterate = function(fn, reverse) {var this$0 = this; - return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse); - }; - - Set.prototype.__iterator = function(type, reverse) { - return this._map.map(function(_, k) {return k}).__iterator(type, reverse); - }; - - Set.prototype.__ensureOwner = function(ownerID) { - if (ownerID === this.__ownerID) { - return this; - } - var newMap = this._map.__ensureOwner(ownerID); - if (!ownerID) { - this.__ownerID = ownerID; - this._map = newMap; - return this; - } - return this.__make(newMap, ownerID); - }; - - - function isSet(maybeSet) { - return !!(maybeSet && maybeSet[IS_SET_SENTINEL]); - } - - Set.isSet = isSet; - - var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@'; - - var SetPrototype = Set.prototype; - SetPrototype[IS_SET_SENTINEL] = true; - SetPrototype[DELETE] = SetPrototype.remove; - SetPrototype.mergeDeep = SetPrototype.merge; - SetPrototype.mergeDeepWith = SetPrototype.mergeWith; - SetPrototype.withMutations = MapPrototype.withMutations; - SetPrototype.asMutable = MapPrototype.asMutable; - SetPrototype.asImmutable = MapPrototype.asImmutable; - - SetPrototype.__empty = emptySet; - SetPrototype.__make = makeSet; - - function updateSet(set, newMap) { - if (set.__ownerID) { - set.size = newMap.size; - set._map = newMap; - return set; - } - return newMap === set._map ? set : - newMap.size === 0 ? set.__empty() : - set.__make(newMap); - } - - function makeSet(map, ownerID) { - var set = Object.create(SetPrototype); - set.size = map ? map.size : 0; - set._map = map; - set.__ownerID = ownerID; - return set; - } - - var EMPTY_SET; - function emptySet() { - return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap())); - } - - createClass(OrderedSet, Set); - - // @pragma Construction - - function OrderedSet(value) { - return value === null || value === undefined ? emptyOrderedSet() : - isOrderedSet(value) ? value : - emptyOrderedSet().withMutations(function(set ) { - var iter = SetIterable(value); - assertNotInfinite(iter.size); - iter.forEach(function(v ) {return set.add(v)}); - }); - } - - OrderedSet.of = function(/*...values*/) { - return this(arguments); - }; - - OrderedSet.fromKeys = function(value) { - return this(KeyedIterable(value).keySeq()); - }; - - OrderedSet.prototype.toString = function() { - return this.__toString('OrderedSet {', '}'); - }; - - - function isOrderedSet(maybeOrderedSet) { - return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet); - } - - OrderedSet.isOrderedSet = isOrderedSet; - - var OrderedSetPrototype = OrderedSet.prototype; - OrderedSetPrototype[IS_ORDERED_SENTINEL] = true; - - OrderedSetPrototype.__empty = emptyOrderedSet; - OrderedSetPrototype.__make = makeOrderedSet; - - function makeOrderedSet(map, ownerID) { - var set = Object.create(OrderedSetPrototype); - set.size = map ? map.size : 0; - set._map = map; - set.__ownerID = ownerID; - return set; - } - - var EMPTY_ORDERED_SET; - function emptyOrderedSet() { - return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap())); - } - - createClass(Stack, IndexedCollection); - - // @pragma Construction - - function Stack(value) { - return value === null || value === undefined ? emptyStack() : - isStack(value) ? value : - emptyStack().unshiftAll(value); - } - - Stack.of = function(/*...values*/) { - return this(arguments); - }; - - Stack.prototype.toString = function() { - return this.__toString('Stack [', ']'); - }; - - // @pragma Access - - Stack.prototype.get = function(index, notSetValue) { - var head = this._head; - index = wrapIndex(this, index); - while (head && index--) { - head = head.next; - } - return head ? head.value : notSetValue; - }; - - Stack.prototype.peek = function() { - return this._head && this._head.value; - }; - - // @pragma Modification - - Stack.prototype.push = function(/*...values*/) { - if (arguments.length === 0) { - return this; - } - var newSize = this.size + arguments.length; - var head = this._head; - for (var ii = arguments.length - 1; ii >= 0; ii--) { - head = { - value: arguments[ii], - next: head - }; - } - if (this.__ownerID) { - this.size = newSize; - this._head = head; - this.__hash = undefined; - this.__altered = true; - return this; - } - return makeStack(newSize, head); - }; - - Stack.prototype.pushAll = function(iter) { - iter = IndexedIterable(iter); - if (iter.size === 0) { - return this; - } - assertNotInfinite(iter.size); - var newSize = this.size; - var head = this._head; - iter.reverse().forEach(function(value ) { - newSize++; - head = { - value: value, - next: head - }; - }); - if (this.__ownerID) { - this.size = newSize; - this._head = head; - this.__hash = undefined; - this.__altered = true; - return this; - } - return makeStack(newSize, head); - }; - - Stack.prototype.pop = function() { - return this.slice(1); - }; - - Stack.prototype.unshift = function(/*...values*/) { - return this.push.apply(this, arguments); - }; - - Stack.prototype.unshiftAll = function(iter) { - return this.pushAll(iter); - }; - - Stack.prototype.shift = function() { - return this.pop.apply(this, arguments); - }; - - Stack.prototype.clear = function() { - if (this.size === 0) { - return this; - } - if (this.__ownerID) { - this.size = 0; - this._head = undefined; - this.__hash = undefined; - this.__altered = true; - return this; - } - return emptyStack(); - }; - - Stack.prototype.slice = function(begin, end) { - if (wholeSlice(begin, end, this.size)) { - return this; - } - var resolvedBegin = resolveBegin(begin, this.size); - var resolvedEnd = resolveEnd(end, this.size); - if (resolvedEnd !== this.size) { - // super.slice(begin, end); - return IndexedCollection.prototype.slice.call(this, begin, end); - } - var newSize = this.size - resolvedBegin; - var head = this._head; - while (resolvedBegin--) { - head = head.next; - } - if (this.__ownerID) { - this.size = newSize; - this._head = head; - this.__hash = undefined; - this.__altered = true; - return this; - } - return makeStack(newSize, head); - }; - - // @pragma Mutability - - Stack.prototype.__ensureOwner = function(ownerID) { - if (ownerID === this.__ownerID) { - return this; - } - if (!ownerID) { - this.__ownerID = ownerID; - this.__altered = false; - return this; - } - return makeStack(this.size, this._head, ownerID, this.__hash); - }; - - // @pragma Iteration - - Stack.prototype.__iterate = function(fn, reverse) { - if (reverse) { - return this.reverse().__iterate(fn); - } - var iterations = 0; - var node = this._head; - while (node) { - if (fn(node.value, iterations++, this) === false) { - break; - } - node = node.next; - } - return iterations; - }; - - Stack.prototype.__iterator = function(type, reverse) { - if (reverse) { - return this.reverse().__iterator(type); - } - var iterations = 0; - var node = this._head; - return new Iterator(function() { - if (node) { - var value = node.value; - node = node.next; - return iteratorValue(type, iterations++, value); - } - return iteratorDone(); - }); - }; - - - function isStack(maybeStack) { - return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]); - } - - Stack.isStack = isStack; - - var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@'; - - var StackPrototype = Stack.prototype; - StackPrototype[IS_STACK_SENTINEL] = true; - StackPrototype.withMutations = MapPrototype.withMutations; - StackPrototype.asMutable = MapPrototype.asMutable; - StackPrototype.asImmutable = MapPrototype.asImmutable; - StackPrototype.wasAltered = MapPrototype.wasAltered; - - - function makeStack(size, head, ownerID, hash) { - var map = Object.create(StackPrototype); - map.size = size; - map._head = head; - map.__ownerID = ownerID; - map.__hash = hash; - map.__altered = false; - return map; - } - - var EMPTY_STACK; - function emptyStack() { - return EMPTY_STACK || (EMPTY_STACK = makeStack(0)); - } - - /** - * Contributes additional methods to a constructor - */ - function mixin(ctor, methods) { - var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; }; - Object.keys(methods).forEach(keyCopier); - Object.getOwnPropertySymbols && - Object.getOwnPropertySymbols(methods).forEach(keyCopier); - return ctor; - } - - Iterable.Iterator = Iterator; - - mixin(Iterable, { - - // ### Conversion to other types - - toArray: function() { - assertNotInfinite(this.size); - var array = new Array(this.size || 0); - this.valueSeq().__iterate(function(v, i) { array[i] = v; }); - return array; - }, - - toIndexedSeq: function() { - return new ToIndexedSequence(this); - }, - - toJS: function() { - return this.toSeq().map( - function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value} - ).__toJS(); - }, - - toJSON: function() { - return this.toSeq().map( - function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value} - ).__toJS(); - }, - - toKeyedSeq: function() { - return new ToKeyedSequence(this, true); - }, - - toMap: function() { - // Use Late Binding here to solve the circular dependency. - return Map(this.toKeyedSeq()); - }, - - toObject: function() { - assertNotInfinite(this.size); - var object = {}; - this.__iterate(function(v, k) { object[k] = v; }); - return object; - }, - - toOrderedMap: function() { - // Use Late Binding here to solve the circular dependency. - return OrderedMap(this.toKeyedSeq()); - }, - - toOrderedSet: function() { - // Use Late Binding here to solve the circular dependency. - return OrderedSet(isKeyed(this) ? this.valueSeq() : this); - }, - - toSet: function() { - // Use Late Binding here to solve the circular dependency. - return Set(isKeyed(this) ? this.valueSeq() : this); - }, - - toSetSeq: function() { - return new ToSetSequence(this); - }, - - toSeq: function() { - return isIndexed(this) ? this.toIndexedSeq() : - isKeyed(this) ? this.toKeyedSeq() : - this.toSetSeq(); - }, - - toStack: function() { - // Use Late Binding here to solve the circular dependency. - return Stack(isKeyed(this) ? this.valueSeq() : this); - }, - - toList: function() { - // Use Late Binding here to solve the circular dependency. - return List(isKeyed(this) ? this.valueSeq() : this); - }, - - - // ### Common JavaScript methods and properties - - toString: function() { - return '[Iterable]'; - }, - - __toString: function(head, tail) { - if (this.size === 0) { - return head + tail; - } - return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail; - }, - - - // ### ES6 Collection methods (ES6 Array and Map) - - concat: function() {var values = SLICE$0.call(arguments, 0); - return reify(this, concatFactory(this, values)); - }, - - includes: function(searchValue) { - return this.some(function(value ) {return is(value, searchValue)}); - }, - - entries: function() { - return this.__iterator(ITERATE_ENTRIES); - }, - - every: function(predicate, context) { - assertNotInfinite(this.size); - var returnValue = true; - this.__iterate(function(v, k, c) { - if (!predicate.call(context, v, k, c)) { - returnValue = false; - return false; - } - }); - return returnValue; - }, - - filter: function(predicate, context) { - return reify(this, filterFactory(this, predicate, context, true)); - }, - - find: function(predicate, context, notSetValue) { - var entry = this.findEntry(predicate, context); - return entry ? entry[1] : notSetValue; - }, - - forEach: function(sideEffect, context) { - assertNotInfinite(this.size); - return this.__iterate(context ? sideEffect.bind(context) : sideEffect); - }, - - join: function(separator) { - assertNotInfinite(this.size); - separator = separator !== undefined ? '' + separator : ','; - var joined = ''; - var isFirst = true; - this.__iterate(function(v ) { - isFirst ? (isFirst = false) : (joined += separator); - joined += v !== null && v !== undefined ? v.toString() : ''; - }); - return joined; - }, - - keys: function() { - return this.__iterator(ITERATE_KEYS); - }, - - map: function(mapper, context) { - return reify(this, mapFactory(this, mapper, context)); - }, - - reduce: function(reducer, initialReduction, context) { - assertNotInfinite(this.size); - var reduction; - var useFirst; - if (arguments.length < 2) { - useFirst = true; - } else { - reduction = initialReduction; - } - this.__iterate(function(v, k, c) { - if (useFirst) { - useFirst = false; - reduction = v; - } else { - reduction = reducer.call(context, reduction, v, k, c); - } - }); - return reduction; - }, - - reduceRight: function(reducer, initialReduction, context) { - var reversed = this.toKeyedSeq().reverse(); - return reversed.reduce.apply(reversed, arguments); - }, - - reverse: function() { - return reify(this, reverseFactory(this, true)); - }, - - slice: function(begin, end) { - return reify(this, sliceFactory(this, begin, end, true)); - }, - - some: function(predicate, context) { - return !this.every(not(predicate), context); - }, - - sort: function(comparator) { - return reify(this, sortFactory(this, comparator)); - }, - - values: function() { - return this.__iterator(ITERATE_VALUES); - }, - - - // ### More sequential methods - - butLast: function() { - return this.slice(0, -1); - }, - - isEmpty: function() { - return this.size !== undefined ? this.size === 0 : !this.some(function() {return true}); - }, - - count: function(predicate, context) { - return ensureSize( - predicate ? this.toSeq().filter(predicate, context) : this - ); - }, - - countBy: function(grouper, context) { - return countByFactory(this, grouper, context); - }, - - equals: function(other) { - return deepEqual(this, other); - }, - - entrySeq: function() { - var iterable = this; - if (iterable._cache) { - // We cache as an entries array, so we can just return the cache! - return new ArraySeq(iterable._cache); - } - var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq(); - entriesSequence.fromEntrySeq = function() {return iterable.toSeq()}; - return entriesSequence; - }, - - filterNot: function(predicate, context) { - return this.filter(not(predicate), context); - }, - - findEntry: function(predicate, context, notSetValue) { - var found = notSetValue; - this.__iterate(function(v, k, c) { - if (predicate.call(context, v, k, c)) { - found = [k, v]; - return false; - } - }); - return found; - }, - - findKey: function(predicate, context) { - var entry = this.findEntry(predicate, context); - return entry && entry[0]; - }, - - findLast: function(predicate, context, notSetValue) { - return this.toKeyedSeq().reverse().find(predicate, context, notSetValue); - }, - - findLastEntry: function(predicate, context, notSetValue) { - return this.toKeyedSeq().reverse().findEntry(predicate, context, notSetValue); - }, - - findLastKey: function(predicate, context) { - return this.toKeyedSeq().reverse().findKey(predicate, context); - }, - - first: function() { - return this.find(returnTrue); - }, - - flatMap: function(mapper, context) { - return reify(this, flatMapFactory(this, mapper, context)); - }, - - flatten: function(depth) { - return reify(this, flattenFactory(this, depth, true)); - }, - - fromEntrySeq: function() { - return new FromEntriesSequence(this); - }, - - get: function(searchKey, notSetValue) { - return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue); - }, - - getIn: function(searchKeyPath, notSetValue) { - var nested = this; - // Note: in an ES6 environment, we would prefer: - // for (var key of searchKeyPath) { - var iter = forceIterator(searchKeyPath); - var step; - while (!(step = iter.next()).done) { - var key = step.value; - nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET; - if (nested === NOT_SET) { - return notSetValue; - } - } - return nested; - }, - - groupBy: function(grouper, context) { - return groupByFactory(this, grouper, context); - }, - - has: function(searchKey) { - return this.get(searchKey, NOT_SET) !== NOT_SET; - }, - - hasIn: function(searchKeyPath) { - return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET; - }, - - isSubset: function(iter) { - iter = typeof iter.includes === 'function' ? iter : Iterable(iter); - return this.every(function(value ) {return iter.includes(value)}); - }, - - isSuperset: function(iter) { - iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter); - return iter.isSubset(this); - }, - - keyOf: function(searchValue) { - return this.findKey(function(value ) {return is(value, searchValue)}); - }, - - keySeq: function() { - return this.toSeq().map(keyMapper).toIndexedSeq(); - }, - - last: function() { - return this.toSeq().reverse().first(); - }, - - lastKeyOf: function(searchValue) { - return this.toKeyedSeq().reverse().keyOf(searchValue); - }, - - max: function(comparator) { - return maxFactory(this, comparator); - }, - - maxBy: function(mapper, comparator) { - return maxFactory(this, comparator, mapper); - }, - - min: function(comparator) { - return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator); - }, - - minBy: function(mapper, comparator) { - return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper); - }, - - rest: function() { - return this.slice(1); - }, - - skip: function(amount) { - return this.slice(Math.max(0, amount)); - }, - - skipLast: function(amount) { - return reify(this, this.toSeq().reverse().skip(amount).reverse()); - }, - - skipWhile: function(predicate, context) { - return reify(this, skipWhileFactory(this, predicate, context, true)); - }, - - skipUntil: function(predicate, context) { - return this.skipWhile(not(predicate), context); - }, - - sortBy: function(mapper, comparator) { - return reify(this, sortFactory(this, comparator, mapper)); - }, - - take: function(amount) { - return this.slice(0, Math.max(0, amount)); - }, - - takeLast: function(amount) { - return reify(this, this.toSeq().reverse().take(amount).reverse()); - }, - - takeWhile: function(predicate, context) { - return reify(this, takeWhileFactory(this, predicate, context)); - }, - - takeUntil: function(predicate, context) { - return this.takeWhile(not(predicate), context); - }, - - valueSeq: function() { - return this.toIndexedSeq(); - }, - - - // ### Hashable Object - - hashCode: function() { - return this.__hash || (this.__hash = hashIterable(this)); - } - - - // ### Internal - - // abstract __iterate(fn, reverse) - - // abstract __iterator(type, reverse) - }); - - // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@'; - // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@'; - // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@'; - // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@'; - - var IterablePrototype = Iterable.prototype; - IterablePrototype[IS_ITERABLE_SENTINEL] = true; - IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values; - IterablePrototype.__toJS = IterablePrototype.toArray; - IterablePrototype.__toStringMapper = quoteString; - IterablePrototype.inspect = - IterablePrototype.toSource = function() { return this.toString(); }; - IterablePrototype.chain = IterablePrototype.flatMap; - IterablePrototype.contains = IterablePrototype.includes; - - mixin(KeyedIterable, { - - // ### More sequential methods - - flip: function() { - return reify(this, flipFactory(this)); - }, - - mapEntries: function(mapper, context) {var this$0 = this; - var iterations = 0; - return reify(this, - this.toSeq().map( - function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)} - ).fromEntrySeq() - ); - }, - - mapKeys: function(mapper, context) {var this$0 = this; - return reify(this, - this.toSeq().flip().map( - function(k, v) {return mapper.call(context, k, v, this$0)} - ).flip() - ); - } - - }); - - var KeyedIterablePrototype = KeyedIterable.prototype; - KeyedIterablePrototype[IS_KEYED_SENTINEL] = true; - KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries; - KeyedIterablePrototype.__toJS = IterablePrototype.toObject; - KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)}; - - - - mixin(IndexedIterable, { - - // ### Conversion to other types - - toKeyedSeq: function() { - return new ToKeyedSequence(this, false); - }, - - - // ### ES6 Collection methods (ES6 Array and Map) - - filter: function(predicate, context) { - return reify(this, filterFactory(this, predicate, context, false)); - }, - - findIndex: function(predicate, context) { - var entry = this.findEntry(predicate, context); - return entry ? entry[0] : -1; - }, - - indexOf: function(searchValue) { - var key = this.keyOf(searchValue); - return key === undefined ? -1 : key; - }, - - lastIndexOf: function(searchValue) { - var key = this.lastKeyOf(searchValue); - return key === undefined ? -1 : key; - }, - - reverse: function() { - return reify(this, reverseFactory(this, false)); - }, - - slice: function(begin, end) { - return reify(this, sliceFactory(this, begin, end, false)); - }, - - splice: function(index, removeNum /*, ...values*/) { - var numArgs = arguments.length; - removeNum = Math.max(removeNum | 0, 0); - if (numArgs === 0 || (numArgs === 2 && !removeNum)) { - return this; - } - // If index is negative, it should resolve relative to the size of the - // collection. However size may be expensive to compute if not cached, so - // only call count() if the number is in fact negative. - index = resolveBegin(index, index < 0 ? this.count() : this.size); - var spliced = this.slice(0, index); - return reify( - this, - numArgs === 1 ? - spliced : - spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum)) - ); - }, - - - // ### More collection methods - - findLastIndex: function(predicate, context) { - var entry = this.findLastEntry(predicate, context); - return entry ? entry[0] : -1; - }, - - first: function() { - return this.get(0); - }, - - flatten: function(depth) { - return reify(this, flattenFactory(this, depth, false)); - }, - - get: function(index, notSetValue) { - index = wrapIndex(this, index); - return (index < 0 || (this.size === Infinity || - (this.size !== undefined && index > this.size))) ? - notSetValue : - this.find(function(_, key) {return key === index}, undefined, notSetValue); - }, - - has: function(index) { - index = wrapIndex(this, index); - return index >= 0 && (this.size !== undefined ? - this.size === Infinity || index < this.size : - this.indexOf(index) !== -1 - ); - }, - - interpose: function(separator) { - return reify(this, interposeFactory(this, separator)); - }, - - interleave: function(/*...iterables*/) { - var iterables = [this].concat(arrCopy(arguments)); - var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables); - var interleaved = zipped.flatten(true); - if (zipped.size) { - interleaved.size = zipped.size * iterables.length; - } - return reify(this, interleaved); - }, - - keySeq: function() { - return Range(0, this.size); - }, - - last: function() { - return this.get(-1); - }, - - skipWhile: function(predicate, context) { - return reify(this, skipWhileFactory(this, predicate, context, false)); - }, - - zip: function(/*, ...iterables */) { - var iterables = [this].concat(arrCopy(arguments)); - return reify(this, zipWithFactory(this, defaultZipper, iterables)); - }, - - zipWith: function(zipper/*, ...iterables */) { - var iterables = arrCopy(arguments); - iterables[0] = this; - return reify(this, zipWithFactory(this, zipper, iterables)); - } - - }); - - IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true; - IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true; - - - - mixin(SetIterable, { - - // ### ES6 Collection methods (ES6 Array and Map) - - get: function(value, notSetValue) { - return this.has(value) ? value : notSetValue; - }, - - includes: function(value) { - return this.has(value); - }, - - - // ### More sequential methods - - keySeq: function() { - return this.valueSeq(); - } - - }); - - SetIterable.prototype.has = IterablePrototype.includes; - SetIterable.prototype.contains = SetIterable.prototype.includes; - - - // Mixin subclasses - - mixin(KeyedSeq, KeyedIterable.prototype); - mixin(IndexedSeq, IndexedIterable.prototype); - mixin(SetSeq, SetIterable.prototype); - - mixin(KeyedCollection, KeyedIterable.prototype); - mixin(IndexedCollection, IndexedIterable.prototype); - mixin(SetCollection, SetIterable.prototype); - - - // #pragma Helper functions - - function keyMapper(v, k) { - return k; - } - - function entryMapper(v, k) { - return [k, v]; - } - - function not(predicate) { - return function() { - return !predicate.apply(this, arguments); - } - } - - function neg(predicate) { - return function() { - return -predicate.apply(this, arguments); - } - } - - function quoteString(value) { - return typeof value === 'string' ? JSON.stringify(value) : String(value); - } - - function defaultZipper() { - return arrCopy(arguments); - } - - function defaultNegComparator(a, b) { - return a < b ? 1 : a > b ? -1 : 0; - } - - function hashIterable(iterable) { - if (iterable.size === Infinity) { - return 0; - } - var ordered = isOrdered(iterable); - var keyed = isKeyed(iterable); - var h = ordered ? 1 : 0; - var size = iterable.__iterate( - keyed ? - ordered ? - function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } : - function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } : - ordered ? - function(v ) { h = 31 * h + hash(v) | 0; } : - function(v ) { h = h + hash(v) | 0; } - ); - return murmurHashOfSize(size, h); - } - - function murmurHashOfSize(size, h) { - h = imul(h, 0xCC9E2D51); - h = imul(h << 15 | h >>> -15, 0x1B873593); - h = imul(h << 13 | h >>> -13, 5); - h = (h + 0xE6546B64 | 0) ^ size; - h = imul(h ^ h >>> 16, 0x85EBCA6B); - h = imul(h ^ h >>> 13, 0xC2B2AE35); - h = smi(h ^ h >>> 16); - return h; - } - - function hashMerge(a, b) { - return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int - } - - var Immutable = { - - Iterable: Iterable, - - Seq: Seq, - Collection: Collection, - Map: Map, - OrderedMap: OrderedMap, - List: List, - Stack: Stack, - Set: Set, - OrderedSet: OrderedSet, - - Record: Record, - Range: Range, - Repeat: Repeat, - - is: is, - fromJS: fromJS - - }; - - return Immutable; - - })); - }); - - var OptionTypes; - (function (OptionTypes) { - OptionTypes[OptionTypes["IGNORED_LABELS"] = 0] = "IGNORED_LABELS"; - OptionTypes[OptionTypes["ACCESSED_NODES"] = 1] = "ACCESSED_NODES"; - OptionTypes[OptionTypes["ARGUMENTS_VARIABLES"] = 2] = "ARGUMENTS_VARIABLES"; - OptionTypes[OptionTypes["ASSIGNED_NODES"] = 3] = "ASSIGNED_NODES"; - OptionTypes[OptionTypes["IGNORE_BREAK_STATEMENTS"] = 4] = "IGNORE_BREAK_STATEMENTS"; - OptionTypes[OptionTypes["IGNORE_RETURN_AWAIT_YIELD"] = 5] = "IGNORE_RETURN_AWAIT_YIELD"; - OptionTypes[OptionTypes["NODES_CALLED_AT_PATH_WITH_OPTIONS"] = 6] = "NODES_CALLED_AT_PATH_WITH_OPTIONS"; - OptionTypes[OptionTypes["REPLACED_VARIABLE_INITS"] = 7] = "REPLACED_VARIABLE_INITS"; - OptionTypes[OptionTypes["RETURN_EXPRESSIONS_ACCESSED_AT_PATH"] = 8] = "RETURN_EXPRESSIONS_ACCESSED_AT_PATH"; - OptionTypes[OptionTypes["RETURN_EXPRESSIONS_ASSIGNED_AT_PATH"] = 9] = "RETURN_EXPRESSIONS_ASSIGNED_AT_PATH"; - OptionTypes[OptionTypes["RETURN_EXPRESSIONS_CALLED_AT_PATH"] = 10] = "RETURN_EXPRESSIONS_CALLED_AT_PATH"; - })(OptionTypes || (OptionTypes = {})); - var RESULT_KEY = {}; - var ExecutionPathOptions = /** @class */ (function () { - function ExecutionPathOptions(optionValues) { - this.optionValues = optionValues; - } - ExecutionPathOptions.create = function () { - return new this(immutable.Map()); - }; - ExecutionPathOptions.prototype.get = function (option) { - return this.optionValues.get(option); - }; - ExecutionPathOptions.prototype.remove = function (option) { - return new ExecutionPathOptions(this.optionValues.remove(option)); - }; - ExecutionPathOptions.prototype.set = function (option, value) { - return new ExecutionPathOptions(this.optionValues.set(option, value)); - }; - ExecutionPathOptions.prototype.setIn = function (optionPath, value) { - return new ExecutionPathOptions(this.optionValues.setIn(optionPath, value)); - }; - ExecutionPathOptions.prototype.addAccessedNodeAtPath = function (path, node) { - return this.setIn([OptionTypes.ACCESSED_NODES, node].concat(path, [RESULT_KEY]), true); - }; - ExecutionPathOptions.prototype.addAccessedReturnExpressionAtPath = function (path, callExpression) { - return this.setIn([OptionTypes.RETURN_EXPRESSIONS_ACCESSED_AT_PATH, callExpression].concat(path, [RESULT_KEY]), true); - }; - ExecutionPathOptions.prototype.addAssignedNodeAtPath = function (path, node) { - return this.setIn([OptionTypes.ASSIGNED_NODES, node].concat(path, [RESULT_KEY]), true); - }; - ExecutionPathOptions.prototype.addAssignedReturnExpressionAtPath = function (path, callExpression) { - return this.setIn([OptionTypes.RETURN_EXPRESSIONS_ASSIGNED_AT_PATH, callExpression].concat(path, [RESULT_KEY]), true); - }; - ExecutionPathOptions.prototype.addCalledNodeAtPathWithOptions = function (path, node, callOptions) { - return this.setIn([OptionTypes.NODES_CALLED_AT_PATH_WITH_OPTIONS, node].concat(path, [RESULT_KEY, callOptions]), true); - }; - ExecutionPathOptions.prototype.addCalledReturnExpressionAtPath = function (path, callExpression) { - return this.setIn([OptionTypes.RETURN_EXPRESSIONS_CALLED_AT_PATH, callExpression].concat(path, [RESULT_KEY]), true); - }; - ExecutionPathOptions.prototype.getArgumentsVariables = function () { - return (this.get(OptionTypes.ARGUMENTS_VARIABLES) || []); - }; - ExecutionPathOptions.prototype.getHasEffectsWhenCalledOptions = function () { - return this.setIgnoreReturnAwaitYield() - .setIgnoreBreakStatements(false) - .setIgnoreNoLabels(); - }; - ExecutionPathOptions.prototype.getReplacedVariableInit = function (variable) { - return this.optionValues.getIn([OptionTypes.REPLACED_VARIABLE_INITS, variable]); - }; - ExecutionPathOptions.prototype.hasNodeBeenAccessedAtPath = function (path, node) { - return this.optionValues.getIn([OptionTypes.ACCESSED_NODES, node].concat(path, [RESULT_KEY])); - }; - ExecutionPathOptions.prototype.hasNodeBeenAssignedAtPath = function (path, node) { - return this.optionValues.getIn([OptionTypes.ASSIGNED_NODES, node].concat(path, [RESULT_KEY])); - }; - ExecutionPathOptions.prototype.hasNodeBeenCalledAtPathWithOptions = function (path, node, callOptions) { - var previousCallOptions = this.optionValues.getIn([ - OptionTypes.NODES_CALLED_AT_PATH_WITH_OPTIONS, - node - ].concat(path, [ - RESULT_KEY - ])); - return (previousCallOptions && - previousCallOptions.find(function (_, otherCallOptions) { - return otherCallOptions.equals(callOptions); - })); - }; - ExecutionPathOptions.prototype.hasReturnExpressionBeenAccessedAtPath = function (path, callExpression) { - return this.optionValues.getIn([ - OptionTypes.RETURN_EXPRESSIONS_ACCESSED_AT_PATH, - callExpression - ].concat(path, [ - RESULT_KEY - ])); - }; - ExecutionPathOptions.prototype.hasReturnExpressionBeenAssignedAtPath = function (path, callExpression) { - return this.optionValues.getIn([ - OptionTypes.RETURN_EXPRESSIONS_ASSIGNED_AT_PATH, - callExpression - ].concat(path, [ - RESULT_KEY - ])); - }; - ExecutionPathOptions.prototype.hasReturnExpressionBeenCalledAtPath = function (path, callExpression) { - return this.optionValues.getIn([ - OptionTypes.RETURN_EXPRESSIONS_CALLED_AT_PATH, - callExpression - ].concat(path, [ - RESULT_KEY - ])); - }; - ExecutionPathOptions.prototype.ignoreBreakStatements = function () { - return this.get(OptionTypes.IGNORE_BREAK_STATEMENTS); - }; - ExecutionPathOptions.prototype.ignoreLabel = function (labelName) { - return this.optionValues.getIn([OptionTypes.IGNORED_LABELS, labelName]); - }; - ExecutionPathOptions.prototype.ignoreReturnAwaitYield = function () { - return this.get(OptionTypes.IGNORE_RETURN_AWAIT_YIELD); - }; - ExecutionPathOptions.prototype.replaceVariableInit = function (variable, init) { - return this.setIn([OptionTypes.REPLACED_VARIABLE_INITS, variable], init); - }; - ExecutionPathOptions.prototype.setArgumentsVariables = function (variables) { - return this.set(OptionTypes.ARGUMENTS_VARIABLES, variables); - }; - ExecutionPathOptions.prototype.setIgnoreBreakStatements = function (value) { - if (value === void 0) { value = true; } - return this.set(OptionTypes.IGNORE_BREAK_STATEMENTS, value); - }; - ExecutionPathOptions.prototype.setIgnoreLabel = function (labelName) { - return this.setIn([OptionTypes.IGNORED_LABELS, labelName], true); - }; - ExecutionPathOptions.prototype.setIgnoreNoLabels = function () { - return this.remove(OptionTypes.IGNORED_LABELS); - }; - ExecutionPathOptions.prototype.setIgnoreReturnAwaitYield = function (value) { - if (value === void 0) { value = true; } - return this.set(OptionTypes.IGNORE_RETURN_AWAIT_YIELD, value); - }; - return ExecutionPathOptions; - }()); - - var keys = { - Program: ['body'], - Literal: [] - }; - function getAndCreateKeys(esTreeNode) { - keys[esTreeNode.type] = Object.keys(esTreeNode).filter(function (key) { return typeof esTreeNode[key] === 'object'; }); - return keys[esTreeNode.type]; - } - - var NEW_EXECUTION_PATH = ExecutionPathOptions.create(); - var NodeBase = /** @class */ (function () { - function NodeBase(esTreeNode, - // we need to pass down the node constructors to avoid a circular dependency - parent, parentScope) { - this.keys = keys[esTreeNode.type] || getAndCreateKeys(esTreeNode); - this.parent = parent; - this.context = parent.context; - this.createScope(parentScope); - this.parseNode(esTreeNode); - this.initialise(); - this.context.magicString.addSourcemapLocation(this.start); - this.context.magicString.addSourcemapLocation(this.end); - } - /** - * Override this to bind assignments to variables and do any initialisations that - * require the scopes to be populated with variables. - */ - NodeBase.prototype.bind = function () { - for (var _i = 0, _a = this.keys; _i < _a.length; _i++) { - var key = _a[_i]; - var value = this[key]; - if (value === null) - continue; - if (Array.isArray(value)) { - for (var _b = 0, value_1 = value; _b < value_1.length; _b++) { - var child = value_1[_b]; - if (child !== null) - child.bind(); - } - } - else { - value.bind(); - } - } - }; - /** - * Override if this node should receive a different scope than the parent scope. - */ - NodeBase.prototype.createScope = function (parentScope) { - this.scope = parentScope; - }; - NodeBase.prototype.declare = function (_kind, _init) { }; - NodeBase.prototype.getLiteralValueAtPath = function (_path, _recursionTracker, _origin) { - return UNKNOWN_VALUE; - }; - NodeBase.prototype.getReturnExpressionWhenCalledAtPath = function (_path, _recursionTracker, _origin) { - return UNKNOWN_EXPRESSION; - }; - NodeBase.prototype.hasEffects = function (options) { - for (var _i = 0, _a = this.keys; _i < _a.length; _i++) { - var key = _a[_i]; - var value = this[key]; - if (value === null) - continue; - if (Array.isArray(value)) { - for (var _b = 0, value_2 = value; _b < value_2.length; _b++) { - var child = value_2[_b]; - if (child !== null && child.hasEffects(options)) - return true; - } - } - else if (value.hasEffects(options)) - return true; - } - return false; - }; - NodeBase.prototype.hasEffectsWhenAccessedAtPath = function (path, _options) { - return path.length > 0; - }; - NodeBase.prototype.hasEffectsWhenAssignedAtPath = function (_path, _options) { - return true; - }; - NodeBase.prototype.hasEffectsWhenCalledAtPath = function (_path, _callOptions, _options) { - return true; - }; - NodeBase.prototype.include = function () { - this.included = true; - for (var _i = 0, _a = this.keys; _i < _a.length; _i++) { - var key = _a[_i]; - var value = this[key]; - if (value === null) - continue; - if (Array.isArray(value)) { - for (var _b = 0, value_3 = value; _b < value_3.length; _b++) { - var child = value_3[_b]; - if (child !== null) - child.include(); - } - } - else { - value.include(); - } - } - }; - NodeBase.prototype.includeWithAllDeclaredVariables = function () { - this.include(); - }; - /** - * Override to perform special initialisation steps after the scope is initialised - */ - NodeBase.prototype.initialise = function () { - this.included = false; - }; - NodeBase.prototype.insertSemicolon = function (code) { - if (code.original[this.end - 1] !== ';') { - code.appendLeft(this.end, ';'); - } - }; - NodeBase.prototype.locate = function () { - // useful for debugging - var location = locate(this.context.code, this.start, { offsetLine: 1 }); - location.file = this.context.fileName; - location.toString = function () { return JSON.stringify(location); }; - return location; - }; - NodeBase.prototype.parseNode = function (esTreeNode) { - for (var _i = 0, _a = Object.keys(esTreeNode); _i < _a.length; _i++) { - var key = _a[_i]; - // That way, we can override this function to add custom initialisation and then call super.parseNode - if (this.hasOwnProperty(key)) - continue; - var value = esTreeNode[key]; - if (typeof value !== 'object' || value === null) { - this[key] = value; - } - else if (Array.isArray(value)) { - this[key] = []; - for (var _b = 0, value_4 = value; _b < value_4.length; _b++) { - var child = value_4[_b]; - this[key].push(child === null - ? null - : new (this.context.nodeConstructors[child.type] || - this.context.nodeConstructors.UnknownNode)(child, this, this.scope)); - } - } - else { - this[key] = new (this.context.nodeConstructors[value.type] || - this.context.nodeConstructors.UnknownNode)(value, this, this.scope); - } - } - }; - NodeBase.prototype.deoptimizePath = function (_path) { }; - NodeBase.prototype.render = function (code, options) { - for (var _i = 0, _a = this.keys; _i < _a.length; _i++) { - var key = _a[_i]; - var value = this[key]; - if (value === null) - continue; - if (Array.isArray(value)) { - for (var _b = 0, value_5 = value; _b < value_5.length; _b++) { - var child = value_5[_b]; - if (child !== null) - child.render(code, options); - } - } - else { - value.render(code, options); - } - } - }; - NodeBase.prototype.shouldBeIncluded = function () { - return this.included || this.hasEffects(NEW_EXECUTION_PATH); - }; - NodeBase.prototype.toString = function () { - return this.context.code.slice(this.start, this.end); - }; - return NodeBase; - }()); - - var ClassNode = /** @class */ (function (_super) { - __extends(ClassNode, _super); - function ClassNode() { - return _super !== null && _super.apply(this, arguments) || this; - } - ClassNode.prototype.createScope = function (parentScope) { - this.scope = new Scope(parentScope); - }; - ClassNode.prototype.hasEffectsWhenAccessedAtPath = function (path, _options) { - return path.length > 1; - }; - ClassNode.prototype.hasEffectsWhenAssignedAtPath = function (path, _options) { - return path.length > 1; - }; - ClassNode.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - return (this.body.hasEffectsWhenCalledAtPath(path, callOptions, options) || - (this.superClass && this.superClass.hasEffectsWhenCalledAtPath(path, callOptions, options))); - }; - ClassNode.prototype.initialise = function () { - this.included = false; - if (this.id !== null) { - this.id.declare('class', this); - } - }; - return ClassNode; - }(NodeBase)); - - function isClassDeclaration(node) { - return node.type === ClassDeclaration; - } - var ClassDeclaration$1 = /** @class */ (function (_super) { - __extends(ClassDeclaration$$1, _super); - function ClassDeclaration$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - ClassDeclaration$$1.prototype.initialise = function () { - _super.prototype.initialise.call(this); - if (this.id !== null) { - this.id.variable.isId = true; - } - }; - ClassDeclaration$$1.prototype.parseNode = function (esTreeNode) { - if (esTreeNode.id !== null) { - this.id = new this.context.nodeConstructors.Identifier(esTreeNode.id, this, this.scope.parent); - } - _super.prototype.parseNode.call(this, esTreeNode); - }; - ClassDeclaration$$1.prototype.render = function (code, options) { - if (options.format === 'system' && this.id && this.id.variable.exportName) { - code.appendLeft(this.end, " exports('" + this.id.variable.exportName + "', " + this.id.variable.getName() + ");"); - } - _super.prototype.render.call(this, code, options); - }; - return ClassDeclaration$$1; - }(ClassNode)); - - var getParameterVariable = function (path, options) { - var firstArgNum = parseInt(path[0], 10); - return ((firstArgNum < options.getArgumentsVariables().length && - options.getArgumentsVariables()[firstArgNum]) || - UNKNOWN_EXPRESSION); - }; - var ArgumentsVariable = /** @class */ (function (_super) { - __extends(ArgumentsVariable, _super); - function ArgumentsVariable(parameters, deoptimizationTracker) { - var _this = _super.call(this, 'arguments', null, UNKNOWN_EXPRESSION, deoptimizationTracker) || this; - _this.parameters = parameters; - return _this; - } - ArgumentsVariable.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - return (path.length > 1 && - getParameterVariable(path, options).hasEffectsWhenAccessedAtPath(path.slice(1), options)); - }; - ArgumentsVariable.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - return (path.length === 0 || - this.included || - getParameterVariable(path, options).hasEffectsWhenAssignedAtPath(path.slice(1), options)); - }; - ArgumentsVariable.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - if (path.length === 0) { - return true; - } - return getParameterVariable(path, options).hasEffectsWhenCalledAtPath(path.slice(1), callOptions, options); - }; - ArgumentsVariable.prototype.deoptimizePath = function (path) { - var firstArgNum = parseInt(path[0], 10); - if (path.length > 0) { - if (firstArgNum >= 0 && this.parameters[firstArgNum]) { - this.parameters[firstArgNum].deoptimizePath(path.slice(1)); - } - } - }; - return ArgumentsVariable; - }(LocalVariable)); - - var ReplaceableInitializationVariable = /** @class */ (function (_super) { - __extends(ReplaceableInitializationVariable, _super); - function ReplaceableInitializationVariable(name, declarator, deoptimizationTracker) { - return _super.call(this, name, declarator, null, deoptimizationTracker) || this; - } - ReplaceableInitializationVariable.prototype.getLiteralValueAtPath = function () { - return UNKNOWN_VALUE; - }; - ReplaceableInitializationVariable.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - return (this._getInit(options).hasEffectsWhenAccessedAtPath(path, options) || - _super.prototype.hasEffectsWhenAccessedAtPath.call(this, path, options)); - }; - ReplaceableInitializationVariable.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - return (this._getInit(options).hasEffectsWhenAssignedAtPath(path, options) || - _super.prototype.hasEffectsWhenAssignedAtPath.call(this, path, options)); - }; - ReplaceableInitializationVariable.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - return (this._getInit(options).hasEffectsWhenCalledAtPath(path, callOptions, options) || - _super.prototype.hasEffectsWhenCalledAtPath.call(this, path, callOptions, options)); - }; - ReplaceableInitializationVariable.prototype._getInit = function (options) { - return options.getReplacedVariableInit(this) || UNKNOWN_EXPRESSION; - }; - return ReplaceableInitializationVariable; - }(LocalVariable)); - - var ThisVariable = /** @class */ (function (_super) { - __extends(ThisVariable, _super); - function ThisVariable(deoptimizationTracker) { - return _super.call(this, 'this', null, deoptimizationTracker) || this; - } - return ThisVariable; - }(ReplaceableInitializationVariable)); - - var ParameterVariable = /** @class */ (function (_super) { - __extends(ParameterVariable, _super); - function ParameterVariable(identifier, deoptimizationTracker) { - return _super.call(this, identifier.name, identifier, deoptimizationTracker) || this; - } - return ParameterVariable; - }(ReplaceableInitializationVariable)); - - var ParameterScope = /** @class */ (function (_super) { - __extends(ParameterScope, _super); - function ParameterScope() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.parameters = []; - return _this; - } - /** - * Adds a parameter to this scope. Parameters must be added in the correct - * order, e.g. from left to right. - * @param {Identifier} identifier - * @returns {Variable} - */ - ParameterScope.prototype.addParameterDeclaration = function (identifier, deoptimizationTracker) { - var variable = new ParameterVariable(identifier, deoptimizationTracker); - this.variables[identifier.name] = variable; - this.parameters.push(variable); - return variable; - }; - ParameterScope.prototype.getParameterVariables = function () { - return this.parameters; - }; - return ParameterScope; - }(Scope)); - - var ReturnValueScope = /** @class */ (function (_super) { - __extends(ReturnValueScope, _super); - function ReturnValueScope() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.returnExpressions = []; - _this.returnExpression = null; - return _this; - } - ReturnValueScope.prototype.addReturnExpression = function (expression) { - this.returnExpressions.push(expression); - }; - ReturnValueScope.prototype.getReturnExpression = function () { - if (this.returnExpression === null) - this.updateReturnExpression(); - return this.returnExpression; - }; - ReturnValueScope.prototype.updateReturnExpression = function () { - if (this.returnExpressions.length === 1) { - this.returnExpression = this.returnExpressions[0]; - } - else { - this.returnExpression = UNKNOWN_EXPRESSION; - for (var _i = 0, _a = this.returnExpressions; _i < _a.length; _i++) { - var expression = _a[_i]; - expression.deoptimizePath(UNKNOWN_PATH); - } - } - }; - return ReturnValueScope; - }(ParameterScope)); - - var FunctionScope = /** @class */ (function (_super) { - __extends(FunctionScope, _super); - function FunctionScope(parent, deoptimizationTracker) { - var _this = _super.call(this, parent) || this; - _this.variables.arguments = new ArgumentsVariable(_super.prototype.getParameterVariables.call(_this), deoptimizationTracker); - _this.variables.this = new ThisVariable(deoptimizationTracker); - return _this; - } - FunctionScope.prototype.findLexicalBoundary = function () { - return this; - }; - FunctionScope.prototype.getOptionsWhenCalledWith = function (_a, options) { - var _this = this; - var args = _a.args, withNew = _a.withNew; - return options - .replaceVariableInit(this.variables.this, withNew ? new UnknownObjectExpression() : UNKNOWN_EXPRESSION) - .setArgumentsVariables(args.map(function (parameter, index) { return _super.prototype.getParameterVariables.call(_this)[index] || parameter; })); - }; - return FunctionScope; - }(ReturnValueScope)); - - var FunctionNode = /** @class */ (function (_super) { - __extends(FunctionNode, _super); - function FunctionNode() { - return _super !== null && _super.apply(this, arguments) || this; - } - FunctionNode.prototype.createScope = function (parentScope) { - this.scope = new FunctionScope(parentScope, this.context.deoptimizationTracker); - }; - FunctionNode.prototype.getReturnExpressionWhenCalledAtPath = function (path) { - return path.length === 0 ? this.scope.getReturnExpression() : UNKNOWN_EXPRESSION; - }; - FunctionNode.prototype.hasEffects = function (options) { - return this.id && this.id.hasEffects(options); - }; - FunctionNode.prototype.hasEffectsWhenAccessedAtPath = function (path) { - if (path.length <= 1) { - return false; - } - return path.length > 2 || path[0] !== 'prototype' || this.isPrototypeDeoptimized; - }; - FunctionNode.prototype.hasEffectsWhenAssignedAtPath = function (path) { - if (path.length <= 1) { - return false; - } - return path.length > 2 || path[0] !== 'prototype' || this.isPrototypeDeoptimized; - }; - FunctionNode.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - if (path.length > 0) { - return true; - } - var innerOptions = this.scope.getOptionsWhenCalledWith(callOptions, options); - for (var _i = 0, _a = this.params; _i < _a.length; _i++) { - var param = _a[_i]; - if (param.hasEffects(innerOptions)) - return true; - } - return this.body.hasEffects(innerOptions); - }; - FunctionNode.prototype.include = function () { - this.scope.variables.arguments.include(); - _super.prototype.include.call(this); - }; - FunctionNode.prototype.initialise = function () { - this.included = false; - this.isPrototypeDeoptimized = false; - if (this.id !== null) { - this.id.declare('function', this); - } - for (var _i = 0, _a = this.params; _i < _a.length; _i++) { - var param = _a[_i]; - param.declare('parameter', UNKNOWN_EXPRESSION); - } - this.body.addImplicitReturnExpressionToScope(); - }; - FunctionNode.prototype.parseNode = function (esTreeNode) { - this.body = (new this.context.nodeConstructors.BlockStatement(esTreeNode.body, this, new Scope(this.scope))); - _super.prototype.parseNode.call(this, esTreeNode); - }; - FunctionNode.prototype.deoptimizePath = function (path) { - if (path.length === 1) { - if (path[0] === 'prototype') { - this.isPrototypeDeoptimized = true; - } - else if (path[0] === UNKNOWN_KEY) { - this.isPrototypeDeoptimized = true; - // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track - // which means the return expression needs to be reassigned as well - this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH); - } - } - }; - return FunctionNode; - }(NodeBase)); - FunctionNode.prototype.preventChildBlockScope = true; - - function isFunctionDeclaration(node) { - return node.type === FunctionDeclaration; - } - var FunctionDeclaration$1 = /** @class */ (function (_super) { - __extends(FunctionDeclaration$$1, _super); - function FunctionDeclaration$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - FunctionDeclaration$$1.prototype.initialise = function () { - _super.prototype.initialise.call(this); - if (this.id !== null) { - this.id.variable.isId = true; - } - }; - FunctionDeclaration$$1.prototype.parseNode = function (esTreeNode) { - if (esTreeNode.id !== null) { - this.id = new this.context.nodeConstructors.Identifier(esTreeNode.id, this, this.scope.parent); - } - _super.prototype.parseNode.call(this, esTreeNode); - }; - return FunctionDeclaration$$1; - }(FunctionNode)); - - function isReference(node, parent) { - if (node.type === 'MemberExpression') { - return !node.computed && isReference(node.object, node); - } - if (node.type === 'Identifier') { - // the only time we could have an identifier node without a parent is - // if it's the entire body of a function without a block statement – - // i.e. an arrow function expression like `a => a` - if (!parent) - return true; - // TODO is this right? - if (parent.type === 'MemberExpression' || parent.type === 'MethodDefinition') { - return parent.computed || node === parent.object; - } - // disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }` - if (parent.type === 'Property') - return parent.computed || node === parent.value; - // disregard the `bar` in `export { foo as bar }` - if (parent.type === 'ExportSpecifier' && node !== parent.local) - return false; - return true; - } - return false; - } - - function isIdentifier(node) { - return node.type === Identifier; - } - var Identifier$1 = /** @class */ (function (_super) { - __extends(Identifier$$1, _super); - function Identifier$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - Identifier$$1.prototype.bind = function () { - if (this.bound) - return; - this.bound = true; - if (this.variable === null && isReference(this, this.parent)) { - this.variable = this.scope.findVariable(this.name); - this.variable.addReference(this); - } - if (this.variable !== null && - this.variable.isLocal && - this.variable.additionalInitializers !== null) { - this.variable.consolidateInitializers(); - } - }; - Identifier$$1.prototype.declare = function (kind, init) { - switch (kind) { - case 'var': - case 'function': - this.variable = this.scope.addDeclaration(this, this.context.deoptimizationTracker, init, true); - break; - case 'let': - case 'const': - case 'class': - this.variable = this.scope.addDeclaration(this, this.context.deoptimizationTracker, init, false); - break; - case 'parameter': - this.variable = this.scope.addParameterDeclaration(this, this.context.deoptimizationTracker); - break; - default: - throw new Error("Unexpected identifier kind " + kind + "."); - } - }; - Identifier$$1.prototype.getLiteralValueAtPath = function (path, recursionTracker, origin) { - if (this.variable !== null) { - return this.variable.getLiteralValueAtPath(path, recursionTracker, origin); - } - return UNKNOWN_VALUE; - }; - Identifier$$1.prototype.getReturnExpressionWhenCalledAtPath = function (path, recursionTracker, origin) { - if (this.variable !== null) { - return this.variable.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin); - } - return UNKNOWN_EXPRESSION; - }; - Identifier$$1.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - return this.variable && this.variable.hasEffectsWhenAccessedAtPath(path, options); - }; - Identifier$$1.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - return !this.variable || this.variable.hasEffectsWhenAssignedAtPath(path, options); - }; - Identifier$$1.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - return !this.variable || this.variable.hasEffectsWhenCalledAtPath(path, callOptions, options); - }; - Identifier$$1.prototype.include = function () { - if (!this.included) { - this.included = true; - if (this.variable !== null && !this.variable.included) { - this.variable.include(); - this.context.requestTreeshakingPass(); - } - } - }; - Identifier$$1.prototype.initialise = function () { - this.included = false; - this.bound = false; - // To avoid later shape mutations - if (!this.variable) { - this.variable = null; - } - }; - Identifier$$1.prototype.deoptimizePath = function (path) { - if (!this.bound) - this.bind(); - if (this.variable !== null) { - if (path.length === 0 && - this.name in this.context.imports && - !this.scope.contains(this.name)) { - this.disallowImportReassignment(); - } - this.variable.deoptimizePath(path); - } - }; - Identifier$$1.prototype.render = function (code, options, _a) { - var _b = _a === void 0 ? BLANK : _a, renderedParentType = _b.renderedParentType, isCalleeOfRenderedParent = _b.isCalleeOfRenderedParent; - if (this.variable) { - var name = this.variable.getName(); - if (name !== this.name) { - code.overwrite(this.start, this.end, name, { - storeName: true, - contentOnly: true - }); - if (this.parent.type === Property && this.parent.shorthand) { - code.prependRight(this.start, this.name + ": "); - } - } - // In strict mode, any variable named "eval" must be the actual "eval" function - if (name === 'eval' && - renderedParentType === CallExpression && - isCalleeOfRenderedParent) { - code.appendRight(this.start, '0, '); - } - if (options.format === 'system' && this.variable.exportName) { - this.renderSystemBindingUpdate(code, name); - } - } - }; - Identifier$$1.prototype.disallowImportReassignment = function () { - this.context.error({ - code: 'ILLEGAL_REASSIGNMENT', - message: "Illegal reassignment to import '" + this.name + "'" - }, this.start); - }; - Identifier$$1.prototype.renderSystemBindingUpdate = function (code, name) { - switch (this.parent.type) { - case AssignmentExpression: - { - var expression = this.parent; - if (expression.left === this) { - code.prependLeft(expression.right.start, "exports('" + this.variable.exportName + "', "); - code.prependRight(expression.right.end, ")"); - } - } - break; - case UpdateExpression: - { - var expression = this.parent; - if (expression.prefix) { - code.overwrite(expression.start, expression.end, "exports('" + this.variable.exportName + "', " + expression.operator + name + ")"); - } - else { - var op = void 0; - switch (expression.operator) { - case '++': - op = name + " + 1"; - break; - case '--': - op = name + " - 1"; - break; - case '**': - op = name + " * " + name; - break; - } - code.overwrite(expression.start, expression.end, "(exports('" + this.variable.exportName + "', " + op + "), " + name + expression.operator + ")"); - } - } - break; - } - }; - return Identifier$$1; - }(NodeBase)); - - var WHITESPACE = /\s/; - // The header ends at the first non-white-space after "default" - function getDeclarationStart(code, start) { - if (start === void 0) { start = 0; } - start = findFirstOccurrenceOutsideComment(code, 'default', start) + 7; - while (WHITESPACE.test(code[start])) - start++; - return start; - } - function getIdInsertPosition(code, declarationKeyword, start) { - if (start === void 0) { start = 0; } - var declarationEnd = findFirstOccurrenceOutsideComment(code, declarationKeyword, start) + declarationKeyword.length; - code = code.slice(declarationEnd, findFirstOccurrenceOutsideComment(code, '{', declarationEnd)); - var generatorStarPos = findFirstOccurrenceOutsideComment(code, '*'); - if (generatorStarPos === -1) { - return declarationEnd; - } - return declarationEnd + generatorStarPos + 1; - } - function isExportDefaultDeclaration(node) { - return node.type === ExportDefaultDeclaration; - } - var ExportDefaultDeclaration$1 = /** @class */ (function (_super) { - __extends(ExportDefaultDeclaration$$1, _super); - function ExportDefaultDeclaration$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - ExportDefaultDeclaration$$1.prototype.bind = function () { - _super.prototype.bind.call(this); - if (this.declarationName && - // Do not set it for Class and FunctionExpressions otherwise they get treeshaken away - (isFunctionDeclaration(this.declaration) || - isClassDeclaration(this.declaration) || - isIdentifier(this.declaration))) { - this.variable.setOriginalVariable(this.scope.findVariable(this.declarationName)); - } - }; - ExportDefaultDeclaration$$1.prototype.initialise = function () { - this.included = false; - this.declarationName = - (this.declaration.id && - this.declaration.id.name) || - this.declaration.name; - this.variable = this.scope.addExportDefaultDeclaration(this.declarationName || this.context.getModuleName(), this, this.context.deoptimizationTracker); - this.context.addExport(this); - }; - ExportDefaultDeclaration$$1.prototype.render = function (code, options, _a) { - var _b = _a === void 0 ? BLANK : _a, start = _b.start, end = _b.end; - var declarationStart = getDeclarationStart(code.original, this.start); - if (isFunctionDeclaration(this.declaration)) { - this.renderNamedDeclaration(code, declarationStart, 'function', this.declaration.id === null, options); - } - else if (isClassDeclaration(this.declaration)) { - this.renderNamedDeclaration(code, declarationStart, 'class', this.declaration.id === null, options); - } - else if (this.variable.referencesOriginal()) { - // Remove altogether to prevent re-declaring the same variable - if (options.format === 'system' && this.variable.exportName) { - code.overwrite(start, end, "exports('" + this.variable.exportName + "', " + this.variable.getName() + ");"); - } - else { - code.remove(start, end); - } - return; - } - else if (this.variable.included) { - this.renderVariableDeclaration(code, declarationStart, options); - } - else { - code.remove(this.start, declarationStart); - this.declaration.render(code, options, { - renderedParentType: ExpressionStatement, - isCalleeOfRenderedParent: false - }); - if (code.original[this.end - 1] !== ';') { - code.appendLeft(this.end, ';'); - } - return; - } - this.declaration.render(code, options); - }; - ExportDefaultDeclaration$$1.prototype.renderNamedDeclaration = function (code, declarationStart, declarationKeyword, needsId, options) { - var name = this.variable.getName(); - // Remove `export default` - code.remove(this.start, declarationStart); - if (needsId) { - code.appendLeft(getIdInsertPosition(code.original, declarationKeyword, declarationStart), " " + name); - } - if (options.format === 'system' && - isClassDeclaration(this.declaration) && - this.variable.exportName) { - code.appendLeft(this.end, " exports('" + this.variable.exportName + "', " + name + ");"); - } - }; - ExportDefaultDeclaration$$1.prototype.renderVariableDeclaration = function (code, declarationStart, options) { - var systemBinding = options.format === 'system' && this.variable.exportName - ? "exports('" + this.variable.exportName + "', " - : ''; - code.overwrite(this.start, declarationStart, this.context.varOrConst + " " + this.variable.getName() + " = " + systemBinding); - var hasTrailingSemicolon = code.original.charCodeAt(this.end - 1) === 59; /*";"*/ - if (systemBinding) { - code.appendRight(hasTrailingSemicolon ? this.end - 1 : this.end, ')' + (hasTrailingSemicolon ? '' : ';')); - } - else if (!hasTrailingSemicolon) { - code.appendLeft(this.end, ';'); - } - }; - return ExportDefaultDeclaration$$1; - }(NodeBase)); - ExportDefaultDeclaration$1.prototype.needsBoundaries = true; - - var ArrayExpression$1 = /** @class */ (function (_super) { - __extends(ArrayExpression, _super); - function ArrayExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - ArrayExpression.prototype.bind = function () { - _super.prototype.bind.call(this); - for (var _i = 0, _a = this.elements; _i < _a.length; _i++) { - var element = _a[_i]; - if (element !== null) - element.deoptimizePath(UNKNOWN_PATH); - } - }; - ArrayExpression.prototype.getReturnExpressionWhenCalledAtPath = function (path) { - if (path.length !== 1) - return UNKNOWN_EXPRESSION; - return getMemberReturnExpressionWhenCalled(arrayMembers, path[0]); - }; - ArrayExpression.prototype.hasEffectsWhenAccessedAtPath = function (path) { - return path.length > 1; - }; - ArrayExpression.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - if (path.length === 1) { - return hasMemberEffectWhenCalled(arrayMembers, path[0], this.included, callOptions, options); - } - return true; - }; - return ArrayExpression; - }(NodeBase)); - - var ArrayPattern$1 = /** @class */ (function (_super) { - __extends(ArrayPattern, _super); - function ArrayPattern() { - return _super !== null && _super.apply(this, arguments) || this; - } - ArrayPattern.prototype.declare = function (kind, _init) { - for (var _i = 0, _a = this.elements; _i < _a.length; _i++) { - var element = _a[_i]; - if (element !== null) { - element.declare(kind, UNKNOWN_EXPRESSION); - } - } - }; - ArrayPattern.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - if (path.length > 0) - return true; - for (var _i = 0, _a = this.elements; _i < _a.length; _i++) { - var element = _a[_i]; - if (element !== null && element.hasEffectsWhenAssignedAtPath(EMPTY_PATH, options)) - return true; - } - return false; - }; - ArrayPattern.prototype.deoptimizePath = function (path) { - if (path.length === 0) { - for (var _i = 0, _a = this.elements; _i < _a.length; _i++) { - var element = _a[_i]; - if (element !== null) { - element.deoptimizePath(path); - } - } - } - }; - return ArrayPattern; - }(NodeBase)); - - var BlockScope = /** @class */ (function (_super) { - __extends(BlockScope, _super); - function BlockScope() { - return _super !== null && _super.apply(this, arguments) || this; - } - BlockScope.prototype.addDeclaration = function (identifier, deoptimizationTracker, init, isHoisted) { - if (init === void 0) { init = null; } - if (isHoisted === void 0) { isHoisted = false; } - if (isHoisted) { - return this.parent.addDeclaration(identifier, deoptimizationTracker, init, true); - } - else { - return _super.prototype.addDeclaration.call(this, identifier, deoptimizationTracker, init, false); - } - }; - return BlockScope; - }(Scope)); - - var BlockStatement$1 = /** @class */ (function (_super) { - __extends(BlockStatement$$1, _super); - function BlockStatement$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - BlockStatement$$1.prototype.addImplicitReturnExpressionToScope = function () { - var lastStatement = this.body[this.body.length - 1]; - if (!lastStatement || lastStatement.type !== ReturnStatement) { - this.scope.addReturnExpression(UNKNOWN_EXPRESSION); - } - }; - BlockStatement$$1.prototype.createScope = function (parentScope) { - this.scope = this.parent.preventChildBlockScope - ? parentScope - : new BlockScope(parentScope); - }; - BlockStatement$$1.prototype.hasEffects = function (options) { - for (var _i = 0, _a = this.body; _i < _a.length; _i++) { - var node = _a[_i]; - if (node.hasEffects(options)) - return true; - } - }; - BlockStatement$$1.prototype.include = function () { - this.included = true; - for (var _i = 0, _a = this.body; _i < _a.length; _i++) { - var node = _a[_i]; - if (node.shouldBeIncluded()) - node.include(); - } - }; - BlockStatement$$1.prototype.render = function (code, options) { - if (this.body.length) { - renderStatementList(this.body, code, this.start + 1, this.end - 1, options); - } - else { - _super.prototype.render.call(this, code, options); - } - }; - return BlockStatement$$1; - }(NodeBase)); - - var ArrowFunctionExpression$1 = /** @class */ (function (_super) { - __extends(ArrowFunctionExpression$$1, _super); - function ArrowFunctionExpression$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - ArrowFunctionExpression$$1.prototype.createScope = function (parentScope) { - this.scope = new ReturnValueScope(parentScope); - }; - ArrowFunctionExpression$$1.prototype.getReturnExpressionWhenCalledAtPath = function (path) { - return path.length === 0 ? this.scope.getReturnExpression() : UNKNOWN_EXPRESSION; - }; - ArrowFunctionExpression$$1.prototype.hasEffects = function (_options) { - return false; - }; - ArrowFunctionExpression$$1.prototype.hasEffectsWhenAccessedAtPath = function (path, _options) { - return path.length > 1; - }; - ArrowFunctionExpression$$1.prototype.hasEffectsWhenAssignedAtPath = function (path, _options) { - return path.length > 1; - }; - ArrowFunctionExpression$$1.prototype.hasEffectsWhenCalledAtPath = function (path, _callOptions, options) { - if (path.length > 0) { - return true; - } - for (var _i = 0, _a = this.params; _i < _a.length; _i++) { - var param = _a[_i]; - if (param.hasEffects(options)) - return true; - } - return this.body.hasEffects(options); - }; - ArrowFunctionExpression$$1.prototype.initialise = function () { - this.included = false; - for (var _i = 0, _a = this.params; _i < _a.length; _i++) { - var param = _a[_i]; - param.declare('parameter', UNKNOWN_EXPRESSION); - } - if (this.body instanceof BlockStatement$1) { - this.body.addImplicitReturnExpressionToScope(); - } - else { - this.scope.addReturnExpression(this.body); - } - }; - ArrowFunctionExpression$$1.prototype.parseNode = function (esTreeNode) { - if (esTreeNode.body.type === BlockStatement) { - this.body = new this.context.nodeConstructors.BlockStatement(esTreeNode.body, this, new Scope(this.scope)); - } - _super.prototype.parseNode.call(this, esTreeNode); - }; - ArrowFunctionExpression$$1.prototype.deoptimizePath = function (path) { - // A reassignment of UNKNOWN_PATH is considered equivalent to having lost track - // which means the return expression needs to be reassigned - if (path.length === 1 && path[0] === UNKNOWN_KEY) { - this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH); - } - }; - return ArrowFunctionExpression$$1; - }(NodeBase)); - ArrowFunctionExpression$1.prototype.preventChildBlockScope = true; - - var AssignmentExpression$1 = /** @class */ (function (_super) { - __extends(AssignmentExpression, _super); - function AssignmentExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - AssignmentExpression.prototype.bind = function () { - _super.prototype.bind.call(this); - this.left.deoptimizePath(EMPTY_PATH); - // We cannot propagate mutations of the new binding to the old binding with certainty - this.right.deoptimizePath(UNKNOWN_PATH); - }; - AssignmentExpression.prototype.hasEffects = function (options) { - return (this.right.hasEffects(options) || - this.left.hasEffects(options) || - this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, options)); - }; - AssignmentExpression.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - return path.length > 0 && this.right.hasEffectsWhenAccessedAtPath(path, options); - }; - return AssignmentExpression; - }(NodeBase)); - - var AssignmentPattern$1 = /** @class */ (function (_super) { - __extends(AssignmentPattern, _super); - function AssignmentPattern() { - return _super !== null && _super.apply(this, arguments) || this; - } - AssignmentPattern.prototype.bind = function () { - _super.prototype.bind.call(this); - this.left.deoptimizePath(EMPTY_PATH); - this.right.deoptimizePath(UNKNOWN_PATH); - }; - AssignmentPattern.prototype.declare = function (kind, init) { - this.left.declare(kind, init); - }; - AssignmentPattern.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - return path.length > 0 || this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, options); - }; - AssignmentPattern.prototype.deoptimizePath = function (path) { - path.length === 0 && this.left.deoptimizePath(path); - }; - return AssignmentPattern; - }(NodeBase)); - - var AwaitExpression$1 = /** @class */ (function (_super) { - __extends(AwaitExpression, _super); - function AwaitExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - AwaitExpression.prototype.include = function () { - _super.prototype.include.call(this); - if (!this.context.usesTopLevelAwait) { - var parent = this.parent; - do { - if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression$1) - return; - } while ((parent = parent.parent)); - this.context.usesTopLevelAwait = true; - } - }; - AwaitExpression.prototype.hasEffects = function (options) { - return _super.prototype.hasEffects.call(this, options) || !options.ignoreReturnAwaitYield(); - }; - AwaitExpression.prototype.render = function (code, options) { - _super.prototype.render.call(this, code, options); - }; - return AwaitExpression; - }(NodeBase)); - - var binaryOperators = { - '==': function (left, right) { return left == right; }, - '!=': function (left, right) { return left != right; }, - '===': function (left, right) { return left === right; }, - '!==': function (left, right) { return left !== right; }, - '<': function (left, right) { return left < right; }, - '<=': function (left, right) { return left <= right; }, - '>': function (left, right) { return left > right; }, - '>=': function (left, right) { return left >= right; }, - '<<': function (left, right) { return left << right; }, - '>>': function (left, right) { return left >> right; }, - '>>>': function (left, right) { return left >>> right; }, - '+': function (left, right) { return left + right; }, - '-': function (left, right) { return left - right; }, - '*': function (left, right) { return left * right; }, - '/': function (left, right) { return left / right; }, - '%': function (left, right) { return left % right; }, - '|': function (left, right) { return left | right; }, - '^': function (left, right) { return left ^ right; }, - '&': function (left, right) { return left & right; }, - '**': function (left, right) { return Math.pow(left, right); }, - in: function (left, right) { return left in right; }, - instanceof: function (left, right) { return left instanceof right; } - }; - var BinaryExpression$1 = /** @class */ (function (_super) { - __extends(BinaryExpression, _super); - function BinaryExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - BinaryExpression.prototype.getLiteralValueAtPath = function (path, recursionTracker, origin) { - if (path.length > 0) - return UNKNOWN_VALUE; - var leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin); - if (leftValue === UNKNOWN_VALUE) - return UNKNOWN_VALUE; - var rightValue = this.right.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin); - if (rightValue === UNKNOWN_VALUE) - return UNKNOWN_VALUE; - var operatorFn = binaryOperators[this.operator]; - if (!operatorFn) - return UNKNOWN_VALUE; - return operatorFn(leftValue, rightValue); - }; - BinaryExpression.prototype.hasEffectsWhenAccessedAtPath = function (path, _options) { - return path.length > 1; - }; - return BinaryExpression; - }(NodeBase)); - - var BreakStatement$1 = /** @class */ (function (_super) { - __extends(BreakStatement, _super); - function BreakStatement() { - return _super !== null && _super.apply(this, arguments) || this; - } - BreakStatement.prototype.hasEffects = function (options) { - return (_super.prototype.hasEffects.call(this, options) || - !options.ignoreBreakStatements() || - (this.label && !options.ignoreLabel(this.label.name))); - }; - return BreakStatement; - }(NodeBase)); - - var RESULT_KEY$1 = {}; - var ImmutableEntityPathTracker = /** @class */ (function () { - function ImmutableEntityPathTracker(existingEntityPaths) { - if (existingEntityPaths === void 0) { existingEntityPaths = immutable.Map(); } - this.entityPaths = existingEntityPaths; - } - ImmutableEntityPathTracker.prototype.isTracked = function (entity, path) { - return this.entityPaths.getIn([entity].concat(path, [RESULT_KEY$1])); - }; - ImmutableEntityPathTracker.prototype.track = function (entity, path) { - return new ImmutableEntityPathTracker(this.entityPaths.setIn([entity].concat(path, [RESULT_KEY$1]), true)); - }; - return ImmutableEntityPathTracker; - }()); - var EMPTY_IMMUTABLE_TRACKER = new ImmutableEntityPathTracker(); - - var CallExpression$1 = /** @class */ (function (_super) { - __extends(CallExpression, _super); - function CallExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - CallExpression.prototype.bind = function () { - _super.prototype.bind.call(this); - if (this.callee instanceof Identifier$1) { - var variable = this.scope.findVariable(this.callee.name); - if (variable.isNamespace) { - this.context.error({ - code: 'CANNOT_CALL_NAMESPACE', - message: "Cannot call a namespace ('" + this.callee.name + "')" - }, this.start); - } - if (this.callee.name === 'eval') { - this.context.warn({ - code: 'EVAL', - message: "Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification", - url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval' - }, this.start); - } - } - if (this.returnExpression === null) { - this.returnExpression = this.callee.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, EMPTY_IMMUTABLE_TRACKER, this); - } - for (var _i = 0, _a = this.arguments; _i < _a.length; _i++) { - var argument = _a[_i]; - // This will make sure all properties of parameters behave as "unknown" - argument.deoptimizePath(UNKNOWN_PATH); - } - }; - CallExpression.prototype.deoptimizeCache = function () { - if (this.returnExpression !== UNKNOWN_EXPRESSION) { - this.returnExpression = UNKNOWN_EXPRESSION; - for (var _i = 0, _a = this.expressionsToBeDeoptimized; _i < _a.length; _i++) { - var expression = _a[_i]; - expression.deoptimizeCache(); - } - } - }; - CallExpression.prototype.getLiteralValueAtPath = function (path, recursionTracker, origin) { - if (this.returnExpression === null) { - this.returnExpression = this.callee.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, recursionTracker, this); - } - if (this.returnExpression === UNKNOWN_EXPRESSION || - recursionTracker.isTracked(this.returnExpression, path)) { - return UNKNOWN_VALUE; - } - this.expressionsToBeDeoptimized.push(origin); - return this.returnExpression.getLiteralValueAtPath(path, recursionTracker.track(this.returnExpression, path), origin); - }; - CallExpression.prototype.getReturnExpressionWhenCalledAtPath = function (path, recursionTracker, origin) { - if (this.returnExpression === null) { - this.returnExpression = this.callee.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, recursionTracker, this); - } - if (this.returnExpression === UNKNOWN_EXPRESSION || - recursionTracker.isTracked(this.returnExpression, path)) { - return UNKNOWN_EXPRESSION; - } - this.expressionsToBeDeoptimized.push(origin); - return this.returnExpression.getReturnExpressionWhenCalledAtPath(path, recursionTracker.track(this.returnExpression, path), origin); - }; - CallExpression.prototype.hasEffects = function (options) { - for (var _i = 0, _a = this.arguments; _i < _a.length; _i++) { - var argument = _a[_i]; - if (argument.hasEffects(options)) - return true; - } - return (this.callee.hasEffects(options) || - this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, options.getHasEffectsWhenCalledOptions())); - }; - CallExpression.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - return (path.length > 0 && - !options.hasReturnExpressionBeenAccessedAtPath(path, this) && - this.returnExpression.hasEffectsWhenAccessedAtPath(path, options.addAccessedReturnExpressionAtPath(path, this))); - }; - CallExpression.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - return (path.length === 0 || - (!options.hasReturnExpressionBeenAssignedAtPath(path, this) && - this.returnExpression.hasEffectsWhenAssignedAtPath(path, options.addAssignedReturnExpressionAtPath(path, this)))); - }; - CallExpression.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - if (options.hasReturnExpressionBeenCalledAtPath(path, this)) - return false; - var innerOptions = options.addCalledReturnExpressionAtPath(path, this); - return (this.hasEffects(innerOptions) || - this.returnExpression.hasEffectsWhenCalledAtPath(path, callOptions, innerOptions)); - }; - CallExpression.prototype.include = function () { - _super.prototype.include.call(this); - if (!this.returnExpression.included) { - this.returnExpression.include(); - } - }; - CallExpression.prototype.initialise = function () { - this.included = false; - this.returnExpression = null; - this.callOptions = CallOptions.create({ - withNew: false, - args: this.arguments, - callIdentifier: this - }); - this.expressionsToBeDeoptimized = []; - }; - CallExpression.prototype.deoptimizePath = function (path) { - if (path.length > 0 && !this.context.deoptimizationTracker.track(this, path)) { - if (this.returnExpression === null) { - this.returnExpression = this.callee.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, EMPTY_IMMUTABLE_TRACKER, this); - } - this.returnExpression.deoptimizePath(path); - } - }; - return CallExpression; - }(NodeBase)); - - var CatchScope = /** @class */ (function (_super) { - __extends(CatchScope, _super); - function CatchScope() { - return _super !== null && _super.apply(this, arguments) || this; - } - CatchScope.prototype.addDeclaration = function (identifier, deoptimizationTracker, init, isHoisted) { - if (init === void 0) { init = null; } - if (isHoisted === void 0) { isHoisted = false; } - if (isHoisted) { - return this.parent.addDeclaration(identifier, deoptimizationTracker, init, true); - } - else { - return _super.prototype.addDeclaration.call(this, identifier, deoptimizationTracker, init, false); - } - }; - return CatchScope; - }(ParameterScope)); - - var CatchClause$1 = /** @class */ (function (_super) { - __extends(CatchClause, _super); - function CatchClause() { - return _super !== null && _super.apply(this, arguments) || this; - } - CatchClause.prototype.createScope = function (parentScope) { - this.scope = new CatchScope(parentScope); - }; - CatchClause.prototype.initialise = function () { - this.included = false; - this.param.declare('parameter', UNKNOWN_EXPRESSION); - }; - CatchClause.prototype.parseNode = function (esTreeNode) { - this.body = new this.context.nodeConstructors.BlockStatement(esTreeNode.body, this, this.scope); - _super.prototype.parseNode.call(this, esTreeNode); - }; - return CatchClause; - }(NodeBase)); - CatchClause$1.prototype.preventChildBlockScope = true; - - var ClassBody$1 = /** @class */ (function (_super) { - __extends(ClassBody, _super); - function ClassBody() { - return _super !== null && _super.apply(this, arguments) || this; - } - ClassBody.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - if (path.length > 0) { - return true; - } - return (this.classConstructor !== null && - this.classConstructor.hasEffectsWhenCalledAtPath(EMPTY_PATH, callOptions, options)); - }; - ClassBody.prototype.initialise = function () { - this.included = false; - for (var _i = 0, _a = this.body; _i < _a.length; _i++) { - var method = _a[_i]; - if (method.kind === 'constructor') { - this.classConstructor = method; - return; - } - } - this.classConstructor = null; - }; - return ClassBody; - }(NodeBase)); - - var ClassExpression$1 = /** @class */ (function (_super) { - __extends(ClassExpression, _super); - function ClassExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - return ClassExpression; - }(ClassNode)); - - var MultiExpression = /** @class */ (function () { - function MultiExpression(expressions) { - this.expressions = expressions; - } - MultiExpression.prototype.getLiteralValueAtPath = function () { - return UNKNOWN_VALUE; - }; - MultiExpression.prototype.getReturnExpressionWhenCalledAtPath = function (path, recursionTracker, origin) { - return new MultiExpression(this.expressions.map(function (expression) { - return expression.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin); - })); - }; - MultiExpression.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - for (var _i = 0, _a = this.expressions; _i < _a.length; _i++) { - var expression = _a[_i]; - if (expression.hasEffectsWhenAccessedAtPath(path, options)) - return true; - } - return false; - }; - MultiExpression.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - for (var _i = 0, _a = this.expressions; _i < _a.length; _i++) { - var expression = _a[_i]; - if (expression.hasEffectsWhenAssignedAtPath(path, options)) - return true; - } - return false; - }; - MultiExpression.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - for (var _i = 0, _a = this.expressions; _i < _a.length; _i++) { - var expression = _a[_i]; - if (expression.hasEffectsWhenCalledAtPath(path, callOptions, options)) - return true; - } - return false; - }; - MultiExpression.prototype.include = function () { }; - MultiExpression.prototype.deoptimizePath = function (path) { - for (var _i = 0, _a = this.expressions; _i < _a.length; _i++) { - var expression = _a[_i]; - expression.deoptimizePath(path); - } - }; - return MultiExpression; - }()); - - var ConditionalExpression$1 = /** @class */ (function (_super) { - __extends(ConditionalExpression, _super); - function ConditionalExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - ConditionalExpression.prototype.bind = function () { - _super.prototype.bind.call(this); - if (!this.isBranchResolutionAnalysed) - this.analyseBranchResolution(); - }; - ConditionalExpression.prototype.deoptimizeCache = function () { - if (this.usedBranch !== null) { - // We did not track if there were reassignments to the previous branch. - // Also, the return value might need to be reassigned. - this.usedBranch = null; - this.unusedBranch.deoptimizePath(UNKNOWN_PATH); - for (var _i = 0, _a = this.expressionsToBeDeoptimized; _i < _a.length; _i++) { - var expression = _a[_i]; - expression.deoptimizeCache(); - } - } - }; - ConditionalExpression.prototype.getLiteralValueAtPath = function (path, recursionTracker, origin) { - if (!this.isBranchResolutionAnalysed) - this.analyseBranchResolution(); - if (this.usedBranch === null) - return UNKNOWN_VALUE; - this.expressionsToBeDeoptimized.push(origin); - return this.usedBranch.getLiteralValueAtPath(path, recursionTracker, origin); - }; - ConditionalExpression.prototype.getReturnExpressionWhenCalledAtPath = function (path, recursionTracker, origin) { - if (!this.isBranchResolutionAnalysed) - this.analyseBranchResolution(); - if (this.usedBranch === null) - return new MultiExpression([ - this.consequent.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin), - this.alternate.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin) - ]); - this.expressionsToBeDeoptimized.push(origin); - return this.usedBranch.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin); - }; - ConditionalExpression.prototype.hasEffects = function (options) { - if (this.test.hasEffects(options)) - return true; - if (this.usedBranch === null) { - return this.consequent.hasEffects(options) || this.alternate.hasEffects(options); - } - return this.usedBranch.hasEffects(options); - }; - ConditionalExpression.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - if (path.length === 0) - return false; - if (this.usedBranch === null) { - return (this.consequent.hasEffectsWhenAccessedAtPath(path, options) || - this.alternate.hasEffectsWhenAccessedAtPath(path, options)); - } - return this.usedBranch.hasEffectsWhenAccessedAtPath(path, options); - }; - ConditionalExpression.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - if (path.length === 0) - return true; - if (this.usedBranch === null) { - return (this.consequent.hasEffectsWhenAssignedAtPath(path, options) || - this.alternate.hasEffectsWhenAssignedAtPath(path, options)); - } - return this.usedBranch.hasEffectsWhenAssignedAtPath(path, options); - }; - ConditionalExpression.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - if (this.usedBranch === null) { - return (this.consequent.hasEffectsWhenCalledAtPath(path, callOptions, options) || - this.alternate.hasEffectsWhenCalledAtPath(path, callOptions, options)); - } - return this.usedBranch.hasEffectsWhenCalledAtPath(path, callOptions, options); - }; - ConditionalExpression.prototype.initialise = function () { - this.included = false; - this.isBranchResolutionAnalysed = false; - this.usedBranch = null; - this.unusedBranch = null; - this.expressionsToBeDeoptimized = []; - }; - ConditionalExpression.prototype.include = function () { - this.included = true; - if (this.usedBranch === null || this.test.shouldBeIncluded()) { - this.test.include(); - this.consequent.include(); - this.alternate.include(); - } - else { - this.usedBranch.include(); - } - }; - ConditionalExpression.prototype.deoptimizePath = function (path) { - if (path.length > 0) { - if (!this.isBranchResolutionAnalysed) - this.analyseBranchResolution(); - if (this.usedBranch === null) { - this.consequent.deoptimizePath(path); - this.alternate.deoptimizePath(path); - } - else { - this.usedBranch.deoptimizePath(path); - } - } - }; - ConditionalExpression.prototype.render = function (code, options, _a) { - var _b = _a === void 0 ? BLANK : _a, renderedParentType = _b.renderedParentType, isCalleeOfRenderedParent = _b.isCalleeOfRenderedParent; - if (!this.test.included) { - code.remove(this.start, this.usedBranch.start); - code.remove(this.usedBranch.end, this.end); - this.usedBranch.render(code, options, { - renderedParentType: renderedParentType || this.parent.type, - isCalleeOfRenderedParent: renderedParentType - ? isCalleeOfRenderedParent - : this.parent.callee === this - }); - } - else { - _super.prototype.render.call(this, code, options); - } - }; - ConditionalExpression.prototype.analyseBranchResolution = function () { - this.isBranchResolutionAnalysed = true; - var testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, EMPTY_IMMUTABLE_TRACKER, this); - if (testValue !== UNKNOWN_VALUE) { - if (testValue) { - this.usedBranch = this.consequent; - this.unusedBranch = this.alternate; - } - else { - this.usedBranch = this.alternate; - this.unusedBranch = this.consequent; - } - } - }; - return ConditionalExpression; - }(NodeBase)); - - var DoWhileStatement$1 = /** @class */ (function (_super) { - __extends(DoWhileStatement, _super); - function DoWhileStatement() { - return _super !== null && _super.apply(this, arguments) || this; - } - DoWhileStatement.prototype.hasEffects = function (options) { - return (this.test.hasEffects(options) || this.body.hasEffects(options.setIgnoreBreakStatements())); - }; - return DoWhileStatement; - }(NodeBase)); - - var EmptyStatement$1 = /** @class */ (function (_super) { - __extends(EmptyStatement$$1, _super); - function EmptyStatement$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - EmptyStatement$$1.prototype.render = function (code, _options) { - if (this.parent.type === BlockStatement || this.parent.type === Program) { - code.remove(this.start, this.end); - } - }; - return EmptyStatement$$1; - }(NodeBase)); - - var ExportAllDeclaration$1 = /** @class */ (function (_super) { - __extends(ExportAllDeclaration, _super); - function ExportAllDeclaration() { - return _super !== null && _super.apply(this, arguments) || this; - } - ExportAllDeclaration.prototype.initialise = function () { - this.included = false; - this.context.addExport(this); - }; - ExportAllDeclaration.prototype.render = function (code, _options, _a) { - var _b = _a === void 0 ? BLANK : _a, start = _b.start, end = _b.end; - code.remove(start, end); - }; - return ExportAllDeclaration; - }(NodeBase)); - ExportAllDeclaration$1.prototype.needsBoundaries = true; - - var ExportNamedDeclaration$1 = /** @class */ (function (_super) { - __extends(ExportNamedDeclaration, _super); - function ExportNamedDeclaration() { - return _super !== null && _super.apply(this, arguments) || this; - } - ExportNamedDeclaration.prototype.bind = function () { - // Do not bind specifiers - if (this.declaration !== null) - this.declaration.bind(); - }; - ExportNamedDeclaration.prototype.hasEffects = function (options) { - return this.declaration && this.declaration.hasEffects(options); - }; - ExportNamedDeclaration.prototype.initialise = function () { - this.included = false; - this.context.addExport(this); - }; - ExportNamedDeclaration.prototype.render = function (code, options, _a) { - var _b = _a === void 0 ? BLANK : _a, start = _b.start, end = _b.end; - if (this.declaration === null) { - code.remove(start, end); - } - else { - code.remove(this.start, this.declaration.start); - this.declaration.render(code, options, { start: start, end: end }); - } - }; - return ExportNamedDeclaration; - }(NodeBase)); - ExportNamedDeclaration$1.prototype.needsBoundaries = true; - - var ExpressionStatement$1 = /** @class */ (function (_super) { - __extends(ExpressionStatement$$1, _super); - function ExpressionStatement$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - ExpressionStatement$$1.prototype.initialise = function () { - this.included = false; - if (this.directive && - this.directive !== 'use strict' && - this.parent.type === Program) { - this.context.warn( - // This is necessary, because either way (deleting or not) can lead to errors. - { - code: 'MODULE_LEVEL_DIRECTIVE', - message: "Module level directives cause errors when bundled, '" + this.directive + "' was ignored." - }, this.start); - } - }; - ExpressionStatement$$1.prototype.shouldBeIncluded = function () { - if (this.directive && this.directive !== 'use strict') - return this.parent.type !== Program; - return _super.prototype.shouldBeIncluded.call(this); - }; - ExpressionStatement$$1.prototype.render = function (code, options) { - _super.prototype.render.call(this, code, options); - if (this.included) - this.insertSemicolon(code); - }; - return ExpressionStatement$$1; - }(NodeBase)); - - var ForInStatement$1 = /** @class */ (function (_super) { - __extends(ForInStatement$$1, _super); - function ForInStatement$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - ForInStatement$$1.prototype.bind = function () { - this.left.bind(); - this.left.deoptimizePath(EMPTY_PATH); - this.right.bind(); - this.body.bind(); - }; - ForInStatement$$1.prototype.createScope = function (parentScope) { - this.scope = new BlockScope(parentScope); - }; - ForInStatement$$1.prototype.hasEffects = function (options) { - return ((this.left && - (this.left.hasEffects(options) || - this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, options))) || - (this.right && this.right.hasEffects(options)) || - this.body.hasEffects(options.setIgnoreBreakStatements())); - }; - ForInStatement$$1.prototype.include = function () { - this.included = true; - this.left.includeWithAllDeclaredVariables(); - this.left.deoptimizePath(EMPTY_PATH); - this.right.include(); - this.body.include(); - }; - ForInStatement$$1.prototype.render = function (code, options) { - this.left.render(code, options, NO_SEMICOLON); - this.right.render(code, options, NO_SEMICOLON); - this.body.render(code, options); - }; - return ForInStatement$$1; - }(NodeBase)); - - var ForOfStatement$1 = /** @class */ (function (_super) { - __extends(ForOfStatement$$1, _super); - function ForOfStatement$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - ForOfStatement$$1.prototype.bind = function () { - this.left.bind(); - this.left.deoptimizePath(EMPTY_PATH); - this.right.bind(); - this.body.bind(); - }; - ForOfStatement$$1.prototype.createScope = function (parentScope) { - this.scope = new BlockScope(parentScope); - }; - ForOfStatement$$1.prototype.hasEffects = function (options) { - return ((this.left && - (this.left.hasEffects(options) || - this.left.hasEffectsWhenAssignedAtPath(EMPTY_PATH, options))) || - (this.right && this.right.hasEffects(options)) || - this.body.hasEffects(options.setIgnoreBreakStatements())); - }; - ForOfStatement$$1.prototype.include = function () { - this.included = true; - this.left.includeWithAllDeclaredVariables(); - this.left.deoptimizePath(EMPTY_PATH); - this.right.include(); - this.body.include(); - }; - ForOfStatement$$1.prototype.render = function (code, options) { - this.left.render(code, options, NO_SEMICOLON); - this.right.render(code, options, NO_SEMICOLON); - this.body.render(code, options); - }; - return ForOfStatement$$1; - }(NodeBase)); - - var ForStatement$1 = /** @class */ (function (_super) { - __extends(ForStatement$$1, _super); - function ForStatement$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - ForStatement$$1.prototype.createScope = function (parentScope) { - this.scope = new BlockScope(parentScope); - }; - ForStatement$$1.prototype.hasEffects = function (options) { - return ((this.init && this.init.hasEffects(options)) || - (this.test && this.test.hasEffects(options)) || - (this.update && this.update.hasEffects(options)) || - this.body.hasEffects(options.setIgnoreBreakStatements())); - }; - ForStatement$$1.prototype.render = function (code, options) { - if (this.init) - this.init.render(code, options, NO_SEMICOLON); - if (this.test) - this.test.render(code, options, NO_SEMICOLON); - if (this.update) - this.update.render(code, options, NO_SEMICOLON); - this.body.render(code, options); - }; - return ForStatement$$1; - }(NodeBase)); - - var FunctionExpression$1 = /** @class */ (function (_super) { - __extends(FunctionExpression, _super); - function FunctionExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - return FunctionExpression; - }(FunctionNode)); - - var IfStatement$1 = /** @class */ (function (_super) { - __extends(IfStatement, _super); - function IfStatement() { - return _super !== null && _super.apply(this, arguments) || this; - } - IfStatement.prototype.bind = function () { - _super.prototype.bind.call(this); - if (!this.isTestValueAnalysed) { - this.testValue = UNKNOWN_VALUE; - this.isTestValueAnalysed = true; - this.testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, EMPTY_IMMUTABLE_TRACKER, this); - } - }; - IfStatement.prototype.deoptimizeCache = function () { - this.testValue = UNKNOWN_VALUE; - }; - IfStatement.prototype.hasEffects = function (options) { - if (this.test.hasEffects(options)) - return true; - if (this.testValue === UNKNOWN_VALUE) { - return (this.consequent.hasEffects(options) || - (this.alternate !== null && this.alternate.hasEffects(options))); - } - return this.testValue - ? this.consequent.hasEffects(options) - : this.alternate !== null && this.alternate.hasEffects(options); - }; - IfStatement.prototype.include = function () { - this.included = true; - if (this.testValue === UNKNOWN_VALUE || this.test.shouldBeIncluded()) { - this.test.include(); - } - if ((this.testValue === UNKNOWN_VALUE || this.testValue) && - this.consequent.shouldBeIncluded()) { - this.consequent.include(); - } - if (this.alternate !== null && - ((this.testValue === UNKNOWN_VALUE || !this.testValue) && this.alternate.shouldBeIncluded())) { - this.alternate.include(); - } - }; - IfStatement.prototype.initialise = function () { - this.included = false; - this.isTestValueAnalysed = false; - }; - IfStatement.prototype.render = function (code, options) { - // Note that unknown test values are always included - if (!this.test.included && - (this.testValue - ? this.alternate === null || !this.alternate.included - : !this.consequent.included)) { - var singleRetainedBranch = this.testValue ? this.consequent : this.alternate; - code.remove(this.start, singleRetainedBranch.start); - code.remove(singleRetainedBranch.end, this.end); - singleRetainedBranch.render(code, options); - } - else { - if (this.test.included) { - this.test.render(code, options); - } - else { - code.overwrite(this.test.start, this.test.end, this.testValue ? 'true' : 'false'); - } - if (this.consequent.included) { - this.consequent.render(code, options); - } - else { - code.overwrite(this.consequent.start, this.consequent.end, ';'); - } - if (this.alternate !== null) { - if (this.alternate.included) { - this.alternate.render(code, options); - } - else { - code.remove(this.consequent.end, this.alternate.end); - } - } - } - }; - return IfStatement; - }(NodeBase)); - - var getDynamicImportMechanism = function (format, compact) { - switch (format) { - case 'cjs': { - var _ = compact ? '' : ' '; - return { - left: 'Promise.resolve(require(', - right: '))', - interopLeft: "Promise.resolve({" + _ + "default:" + _ + "require(", - interopRight: ")" + _ + "})" - }; - } - case 'amd': { - var _ = compact ? '' : ' '; - var resolve = compact ? 'c' : 'resolve'; - var reject = compact ? 'e' : 'reject'; - return { - left: "new Promise(function" + _ + "(" + resolve + "," + _ + reject + ")" + _ + "{" + _ + "require([", - right: "]," + _ + resolve + "," + _ + reject + ")" + _ + "})", - interopLeft: "new Promise(function" + _ + "(" + resolve + "," + _ + reject + ")" + _ + "{" + _ + "require([", - interopRight: "]," + _ + "function" + _ + "(m)" + _ + "{" + _ + resolve + "({" + _ + "default:" + _ + "m" + _ + "})" + _ + "}," + _ + reject + ")" + _ + "})" - }; - } - case 'system': - return { - left: 'module.import(', - right: ')' - }; - } - }; - var Import$1 = /** @class */ (function (_super) { - __extends(Import, _super); - function Import() { - return _super !== null && _super.apply(this, arguments) || this; - } - Import.prototype.initialise = function () { - this.included = false; - this.resolutionNamespace = undefined; - this.resolutionInterop = false; - this.rendered = false; - this.context.addDynamicImport(this); - }; - Import.prototype.renderFinalResolution = function (code, resolution) { - // avoid unnecessary writes when tree-shaken - if (this.rendered) - code.overwrite(this.parent.arguments[0].start, this.parent.arguments[0].end, resolution); - }; - Import.prototype.render = function (code, options) { - this.rendered = true; - if (this.resolutionNamespace) { - var _ = options.compact ? '' : ' '; - var s = options.compact ? '' : ';'; - code.overwrite(this.parent.start, this.parent.end, "Promise.resolve().then(function" + _ + "()" + _ + "{" + _ + "return " + this.resolutionNamespace + s + _ + "})"); - return; - } - var importMechanism = getDynamicImportMechanism(options.format, options.compact); - if (importMechanism) { - var leftMechanism = (this.resolutionInterop && importMechanism.interopLeft) || importMechanism.left; - code.overwrite(this.parent.start, this.parent.arguments[0].start, leftMechanism); - var rightMechanism = (this.resolutionInterop && importMechanism.interopRight) || importMechanism.right; - code.overwrite(this.parent.arguments[0].end, this.parent.end, rightMechanism); - } - }; - Import.prototype.setResolution = function (interop, namespace) { - if (namespace === void 0) { namespace = undefined; } - this.rendered = false; - this.resolutionInterop = interop; - this.resolutionNamespace = namespace; - }; - return Import; - }(NodeBase)); - - var ImportDeclaration$1 = /** @class */ (function (_super) { - __extends(ImportDeclaration, _super); - function ImportDeclaration() { - return _super !== null && _super.apply(this, arguments) || this; - } - ImportDeclaration.prototype.bind = function () { }; - ImportDeclaration.prototype.initialise = function () { - this.included = false; - this.context.addImport(this); - }; - ImportDeclaration.prototype.hasEffects = function () { - return false; - }; - ImportDeclaration.prototype.render = function (code, _options, _a) { - var _b = _a === void 0 ? BLANK : _a, start = _b.start, end = _b.end; - code.remove(start, end); - }; - return ImportDeclaration; - }(NodeBase)); - ImportDeclaration$1.prototype.needsBoundaries = true; - - var LabeledStatement$1 = /** @class */ (function (_super) { - __extends(LabeledStatement, _super); - function LabeledStatement() { - return _super !== null && _super.apply(this, arguments) || this; - } - LabeledStatement.prototype.hasEffects = function (options) { - return this.body.hasEffects(options.setIgnoreLabel(this.label.name).setIgnoreBreakStatements()); - }; - return LabeledStatement; - }(NodeBase)); - - function isLiteral(node) { - return node.type === Literal; - } - var Literal$1 = /** @class */ (function (_super) { - __extends(Literal$$1, _super); - function Literal$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - Literal$$1.prototype.getLiteralValueAtPath = function (path) { - if (path.length > 0) { - return UNKNOWN_VALUE; - } - // not sure why we need this type cast here - return this.value; - }; - Literal$$1.prototype.getReturnExpressionWhenCalledAtPath = function (path) { - if (path.length !== 1) - return UNKNOWN_EXPRESSION; - return getMemberReturnExpressionWhenCalled(this.members, path[0]); - }; - Literal$$1.prototype.hasEffectsWhenAccessedAtPath = function (path) { - if (this.value === null) { - return path.length > 0; - } - return path.length > 1; - }; - Literal$$1.prototype.hasEffectsWhenAssignedAtPath = function (path) { - return path.length > 0; - }; - Literal$$1.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - if (path.length === 1) { - return hasMemberEffectWhenCalled(this.members, path[0], this.included, callOptions, options); - } - return true; - }; - Literal$$1.prototype.initialise = function () { - this.included = false; - this.members = getLiteralMembersForValue(this.value); - }; - Literal$$1.prototype.render = function (code, _options) { - if (typeof this.value === 'string') { - code.indentExclusionRanges.push([this.start + 1, this.end - 1]); - } - }; - return Literal$$1; - }(NodeBase)); - - var LogicalExpression$1 = /** @class */ (function (_super) { - __extends(LogicalExpression, _super); - function LogicalExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - LogicalExpression.prototype.bind = function () { - _super.prototype.bind.call(this); - if (!this.isBranchResolutionAnalysed) - this.analyseBranchResolution(); - }; - LogicalExpression.prototype.deoptimizeCache = function () { - if (this.usedBranch !== null) { - // We did not track if there were reassignments to any of the branches. - // Also, the return values might need reassignment. - this.usedBranch = null; - this.unusedBranch.deoptimizePath(UNKNOWN_PATH); - for (var _i = 0, _a = this.expressionsToBeDeoptimized; _i < _a.length; _i++) { - var expression = _a[_i]; - expression.deoptimizeCache(); - } - } - }; - LogicalExpression.prototype.getLiteralValueAtPath = function (path, recursionTracker, origin) { - if (!this.isBranchResolutionAnalysed) - this.analyseBranchResolution(); - if (this.usedBranch === null) - return UNKNOWN_VALUE; - this.expressionsToBeDeoptimized.push(origin); - return this.usedBranch.getLiteralValueAtPath(path, recursionTracker, origin); - }; - LogicalExpression.prototype.getReturnExpressionWhenCalledAtPath = function (path, recursionTracker, origin) { - if (!this.isBranchResolutionAnalysed) - this.analyseBranchResolution(); - if (this.usedBranch === null) - return new MultiExpression([ - this.left.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin), - this.right.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin) - ]); - this.expressionsToBeDeoptimized.push(origin); - return this.usedBranch.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin); - }; - LogicalExpression.prototype.hasEffects = function (options) { - if (this.usedBranch === null) { - return this.left.hasEffects(options) || this.right.hasEffects(options); - } - return this.usedBranch.hasEffects(options); - }; - LogicalExpression.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - if (path.length === 0) - return false; - if (this.usedBranch === null) { - return (this.left.hasEffectsWhenAccessedAtPath(path, options) || - this.right.hasEffectsWhenAccessedAtPath(path, options)); - } - return this.usedBranch.hasEffectsWhenAccessedAtPath(path, options); - }; - LogicalExpression.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - if (path.length === 0) - return true; - if (this.usedBranch === null) { - return (this.left.hasEffectsWhenAssignedAtPath(path, options) || - this.right.hasEffectsWhenAssignedAtPath(path, options)); - } - return this.usedBranch.hasEffectsWhenAssignedAtPath(path, options); - }; - LogicalExpression.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - if (this.usedBranch === null) { - return (this.left.hasEffectsWhenCalledAtPath(path, callOptions, options) || - this.right.hasEffectsWhenCalledAtPath(path, callOptions, options)); - } - return this.usedBranch.hasEffectsWhenCalledAtPath(path, callOptions, options); - }; - LogicalExpression.prototype.include = function () { - this.included = true; - if (this.usedBranch === null || this.unusedBranch.shouldBeIncluded()) { - this.left.include(); - this.right.include(); - } - else { - this.usedBranch.include(); - } - }; - LogicalExpression.prototype.initialise = function () { - this.included = false; - this.isBranchResolutionAnalysed = false; - this.usedBranch = null; - this.unusedBranch = null; - this.expressionsToBeDeoptimized = []; - }; - LogicalExpression.prototype.deoptimizePath = function (path) { - if (path.length > 0) { - if (!this.isBranchResolutionAnalysed) - this.analyseBranchResolution(); - if (this.usedBranch === null) { - this.left.deoptimizePath(path); - this.right.deoptimizePath(path); - } - else { - this.usedBranch.deoptimizePath(path); - } - } - }; - LogicalExpression.prototype.render = function (code, options, _a) { - var _b = _a === void 0 ? BLANK : _a, renderedParentType = _b.renderedParentType, isCalleeOfRenderedParent = _b.isCalleeOfRenderedParent; - if (!this.left.included || !this.right.included) { - code.remove(this.start, this.usedBranch.start); - code.remove(this.usedBranch.end, this.end); - this.usedBranch.render(code, options, { - renderedParentType: renderedParentType || this.parent.type, - isCalleeOfRenderedParent: renderedParentType - ? isCalleeOfRenderedParent - : this.parent.callee === this - }); - } - else { - _super.prototype.render.call(this, code, options); - } - }; - LogicalExpression.prototype.analyseBranchResolution = function () { - this.isBranchResolutionAnalysed = true; - var leftValue = this.left.getLiteralValueAtPath(EMPTY_PATH, EMPTY_IMMUTABLE_TRACKER, this); - if (leftValue !== UNKNOWN_VALUE) { - if (this.operator === '||' ? leftValue : !leftValue) { - this.usedBranch = this.left; - this.unusedBranch = this.right; - } - else { - this.usedBranch = this.right; - this.unusedBranch = this.left; - } - } - }; - return LogicalExpression; - }(NodeBase)); - - function getAliasName(resolved, unresolved) { - var alias = basename(unresolved || resolved); - var ext = extname(resolved); - if (alias.endsWith(ext)) - alias = alias.substr(0, alias.length - ext.length); - return alias; - } - function relativeId(id) { - if (typeof process === 'undefined' || !isAbsolute(id)) - return id; - return relative(process.cwd(), id); - } - function isPlainName(name) { - // not starting with "./", "/". "../" - if (name[0] === '/' || - (name[1] === '.' && (name[2] === '/' || (name[2] === '.' && name[3] === '/')))) - return false; - // not a URL - if (name.indexOf(':') !== -1) - return false; - return true; - } - - function getResolvablePropertyKey(memberExpression) { - return memberExpression.computed - ? getResolvableComputedPropertyKey(memberExpression.property) - : memberExpression.property.name; - } - function getResolvableComputedPropertyKey(propertyKey) { - if (propertyKey instanceof Literal$1) { - return String(propertyKey.value); - } - return null; - } - function getPathIfNotComputed(memberExpression) { - var nextPathKey = memberExpression.propertyKey; - var object = memberExpression.object; - if (typeof nextPathKey === 'string') { - if (object instanceof Identifier$1) { - return [ - { key: object.name, pos: object.start }, - { key: nextPathKey, pos: memberExpression.property.start } - ]; - } - if (isMemberExpression(object)) { - var parentPath = getPathIfNotComputed(object); - return (parentPath && parentPath.concat([{ key: nextPathKey, pos: memberExpression.property.start }])); - } - } - return null; - } - function isMemberExpression(node) { - return node.type === MemberExpression; - } - var MemberExpression$1 = /** @class */ (function (_super) { - __extends(MemberExpression$$1, _super); - function MemberExpression$$1() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.variable = null; - return _this; - } - MemberExpression$$1.prototype.bind = function () { - if (this.bound) - return; - this.bound = true; - var path = getPathIfNotComputed(this); - var baseVariable = path && this.scope.findVariable(path[0].key); - if (baseVariable && baseVariable.isNamespace) { - var resolvedVariable = this.resolveNamespaceVariables(baseVariable, path.slice(1)); - if (!resolvedVariable) { - _super.prototype.bind.call(this); - } - else if (typeof resolvedVariable === 'string') { - this.replacement = resolvedVariable; - } - else { - if (resolvedVariable.isExternal && resolvedVariable.module) { - resolvedVariable.module.suggestName(path[0].key); - } - this.variable = resolvedVariable; - } - } - else { - _super.prototype.bind.call(this); - if (this.propertyKey === null) - this.analysePropertyKey(); - } - }; - MemberExpression$$1.prototype.deoptimizeCache = function () { - for (var _i = 0, _a = this.expressionsToBeDeoptimized; _i < _a.length; _i++) { - var expression = _a[_i]; - expression.deoptimizeCache(); - } - }; - MemberExpression$$1.prototype.getLiteralValueAtPath = function (path, recursionTracker, origin) { - if (this.variable !== null) { - return this.variable.getLiteralValueAtPath(path, recursionTracker, origin); - } - if (this.propertyKey === null) - this.analysePropertyKey(); - this.expressionsToBeDeoptimized.push(origin); - return this.object.getLiteralValueAtPath([this.propertyKey].concat(path), recursionTracker, origin); - }; - MemberExpression$$1.prototype.getReturnExpressionWhenCalledAtPath = function (path, recursionTracker, origin) { - if (this.variable !== null) { - return this.variable.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin); - } - if (this.propertyKey === null) - this.analysePropertyKey(); - this.expressionsToBeDeoptimized.push(origin); - return this.object.getReturnExpressionWhenCalledAtPath([this.propertyKey].concat(path), recursionTracker, origin); - }; - MemberExpression$$1.prototype.hasEffects = function (options) { - return (this.property.hasEffects(options) || - this.object.hasEffects(options) || - (this.context.propertyReadSideEffects && - this.object.hasEffectsWhenAccessedAtPath([this.propertyKey], options))); - }; - MemberExpression$$1.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - if (path.length === 0) { - return false; - } - if (this.variable !== null) { - return this.variable.hasEffectsWhenAccessedAtPath(path, options); - } - return this.object.hasEffectsWhenAccessedAtPath([this.propertyKey].concat(path), options); - }; - MemberExpression$$1.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - if (this.variable !== null) { - return this.variable.hasEffectsWhenAssignedAtPath(path, options); - } - return this.object.hasEffectsWhenAssignedAtPath([this.propertyKey].concat(path), options); - }; - MemberExpression$$1.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - if (this.variable !== null) { - return this.variable.hasEffectsWhenCalledAtPath(path, callOptions, options); - } - return this.object.hasEffectsWhenCalledAtPath([this.propertyKey].concat(path), callOptions, options); - }; - MemberExpression$$1.prototype.include = function () { - if (!this.included) { - this.included = true; - if (this.variable !== null && !this.variable.included) { - this.variable.include(); - this.context.requestTreeshakingPass(); - } - } - this.object.include(); - this.property.include(); - }; - MemberExpression$$1.prototype.initialise = function () { - this.included = false; - this.propertyKey = getResolvablePropertyKey(this); - this.variable = null; - this.bound = false; - this.replacement = null; - this.expressionsToBeDeoptimized = []; - }; - MemberExpression$$1.prototype.deoptimizePath = function (path) { - if (!this.bound) - this.bind(); - if (path.length === 0) - this.disallowNamespaceReassignment(); - if (this.variable) { - this.variable.deoptimizePath(path); - } - else { - if (this.propertyKey === null) - this.analysePropertyKey(); - this.object.deoptimizePath([this.propertyKey].concat(path)); - } - }; - MemberExpression$$1.prototype.render = function (code, options, _a) { - var _b = _a === void 0 ? BLANK : _a, renderedParentType = _b.renderedParentType, isCalleeOfRenderedParent = _b.isCalleeOfRenderedParent; - var isCalleeOfDifferentParent = renderedParentType === CallExpression && isCalleeOfRenderedParent; - if (this.variable || this.replacement) { - var replacement = this.variable ? this.variable.getName() : this.replacement; - if (isCalleeOfDifferentParent) - replacement = '0, ' + replacement; - code.overwrite(this.start, this.end, replacement, { - storeName: true, - contentOnly: true - }); - } - else { - if (isCalleeOfDifferentParent) { - code.appendRight(this.start, '0, '); - } - _super.prototype.render.call(this, code, options); - } - }; - MemberExpression$$1.prototype.disallowNamespaceReassignment = function () { - if (this.object instanceof Identifier$1 && - this.scope.findVariable(this.object.name).isNamespace) { - this.context.error({ - code: 'ILLEGAL_NAMESPACE_REASSIGNMENT', - message: "Illegal reassignment to import '" + this.object.name + "'" - }, this.start); - } - }; - MemberExpression$$1.prototype.resolveNamespaceVariables = function (baseVariable, path) { - if (path.length === 0) - return baseVariable; - if (!baseVariable.isNamespace) - return null; - var exportName = path[0].key; - var variable = baseVariable.isExternal - ? baseVariable.module.traceExport(exportName) - : baseVariable.context.traceExport(exportName); - if (!variable) { - var fileName = baseVariable.isExternal - ? baseVariable.module.id - : baseVariable.context.fileName; - this.context.warn({ - code: 'MISSING_EXPORT', - missing: exportName, - importer: relativeId(this.context.fileName), - exporter: relativeId(fileName), - message: "'" + exportName + "' is not exported by '" + relativeId(fileName) + "'", - url: "https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module" - }, path[0].pos); - return 'undefined'; - } - return this.resolveNamespaceVariables(variable, path.slice(1)); - }; - MemberExpression$$1.prototype.analysePropertyKey = function () { - this.propertyKey = UNKNOWN_KEY; - var value = this.property.getLiteralValueAtPath(EMPTY_PATH, EMPTY_IMMUTABLE_TRACKER, this); - this.propertyKey = value === UNKNOWN_VALUE ? UNKNOWN_KEY : String(value); - }; - return MemberExpression$$1; - }(NodeBase)); - - var globalImportMetaUrlMechanism = "(typeof document !== 'undefined' ? document.currentScript && document.currentScript.src || document.baseURI : new (typeof URL !== 'undefined' ? URL : require('ur'+'l').URL)('file:' + __filename).href)"; - var importMetaUrlMechanisms = { - amd: "new URL((typeof process !== 'undefined' && process.versions && process.versions.node ? 'file:' : '') + module.uri).href", - cjs: "new (typeof URL !== 'undefined' ? URL : require('ur'+'l').URL)((process.browser ? '' : 'file:') + __filename, process.browser && document.baseURI).href", - iife: globalImportMetaUrlMechanism, - umd: globalImportMetaUrlMechanism - }; - var globalImportMetaUrlMechanismCompact = "(typeof document!=='undefined'?document.currentScript&&document.currentScript.src||document.baseURI:new(typeof URL!=='undefined'?URL:require('ur'+'l').URL)('file:'+__filename).href)"; - var importMetaUrlMechanismsCompact = { - amd: "new URL((typeof process!=='undefined'&&process.versions&&process.versions.node?'file:':'')+module.uri).href", - cjs: "new(typeof URL!=='undefined'?URL:require('ur'+'l').URL)((process.browser?'':'file:')+__filename,process.browser&&document.baseURI).href", - iife: globalImportMetaUrlMechanismCompact, - umd: globalImportMetaUrlMechanismCompact - }; - var globalRelUrlMechanism = function (relPath, compact) { - var _ = compact ? '' : ' '; - return "new" + _ + "(typeof URL" + _ + "!==" + _ + "'undefined'" + _ + "?" + _ + "URL" + _ + ":" + _ + "require('ur'+'l').URL)((typeof document" + _ + "!==" + _ + "'undefined'" + _ + "?" + _ + "document.currentScript" + _ + "&&" + _ + "document.currentScript.src" + _ + "||" + _ + "document.baseURI" + _ + ":" + _ + "'file:'" + _ + "+" + _ + "__filename)" + _ + "+" + _ + "'/../" + relPath + "').href"; - }; - var relUrlMechanisms = { - amd: function (relPath, compact) { - var _ = compact ? '' : ' '; - return "new URL((typeof process" + _ + "!==" + _ + "'undefined'" + _ + "&&" + _ + "process.versions" + _ + "&&" + _ + "process.versions.node" + _ + "?" + _ + "'file:'" + _ + ":" + _ + "'')" + _ + "+" + _ + "module.uri" + _ + "+" + _ + "'/../" + relPath + "').href"; - }, - cjs: function (relPath, compact) { - var _ = compact ? '' : ' '; - return "new" + _ + "(typeof URL" + _ + "!==" + _ + "'undefined'" + _ + "?" + _ + "URL" + _ + ":" + _ + "require('ur'+'l').URL)((process.browser" + _ + "?" + _ + "''" + _ + ":" + _ + "'file:')" + _ + "+" + _ + "__dirname" + _ + "+" + _ + "'/" + relPath + "'," + _ + "process.browser" + _ + "&&" + _ + "document.baseURI).href"; - }, - es: function (relPath, compact) { - var _ = compact ? '' : ' '; - return "new URL('../" + relPath + "'," + _ + "import.meta.url).href"; - }, - system: function (relPath, compact) { - var _ = compact ? '' : ' '; - return "new URL('../" + relPath + "'," + _ + "module.url).href"; - }, - iife: globalRelUrlMechanism, - umd: globalRelUrlMechanism - }; - var MetaProperty$1 = /** @class */ (function (_super) { - __extends(MetaProperty, _super); - function MetaProperty() { - return _super !== null && _super.apply(this, arguments) || this; - } - MetaProperty.prototype.initialise = function () { - if (this.meta.name === 'import') { - this.rendered = false; - this.context.addImportMeta(this); - } - this.included = false; - }; - MetaProperty.prototype.render = function (code, options) { - if (this.meta.name === 'import') - this.rendered = true; - _super.prototype.render.call(this, code, options); - }; - MetaProperty.prototype.renderFinalMechanism = function (code, chunkId, format, compact) { - if (!this.rendered) - return false; - if (this.parent instanceof MemberExpression$1 === false) - return false; - var parent = this.parent; - var importMetaProperty; - if (parent.property instanceof Identifier$1) - importMetaProperty = parent.property.name; - else if (parent.property instanceof Literal$1 && typeof parent.property.value === 'string') - importMetaProperty = parent.property.value; - else - return false; - // support import.meta.ROLLUP_ASSET_URL_[ID] - if (importMetaProperty.startsWith('ROLLUP_ASSET_URL_')) { - var assetFileName = this.context.getAssetFileName(importMetaProperty.substr(17)); - var relPath = normalize(relative(dirname(chunkId), assetFileName)); - code.overwrite(parent.start, parent.end, relUrlMechanisms[format](relPath, compact)); - return true; - } - if (format === 'system') { - code.overwrite(this.meta.start, this.meta.end, 'module'); - } - else if (importMetaProperty === 'url') { - var importMetaUrlMechanism = (compact - ? importMetaUrlMechanismsCompact - : importMetaUrlMechanisms)[format]; - if (importMetaUrlMechanism) - code.overwrite(parent.start, parent.end, importMetaUrlMechanism); - return true; - } - return false; - }; - return MetaProperty; - }(NodeBase)); - - var MethodDefinition$1 = /** @class */ (function (_super) { - __extends(MethodDefinition, _super); - function MethodDefinition() { - return _super !== null && _super.apply(this, arguments) || this; - } - MethodDefinition.prototype.hasEffects = function (options) { - return this.key.hasEffects(options); - }; - MethodDefinition.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - return (path.length > 0 || this.value.hasEffectsWhenCalledAtPath(EMPTY_PATH, callOptions, options)); - }; - return MethodDefinition; - }(NodeBase)); - - var NewExpression$1 = /** @class */ (function (_super) { - __extends(NewExpression, _super); - function NewExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - NewExpression.prototype.bind = function () { - _super.prototype.bind.call(this); - for (var _i = 0, _a = this.arguments; _i < _a.length; _i++) { - var argument = _a[_i]; - // This will make sure all properties of parameters behave as "unknown" - argument.deoptimizePath(UNKNOWN_PATH); - } - }; - NewExpression.prototype.hasEffects = function (options) { - for (var _i = 0, _a = this.arguments; _i < _a.length; _i++) { - var argument = _a[_i]; - if (argument.hasEffects(options)) - return true; - } - return this.callee.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, options.getHasEffectsWhenCalledOptions()); - }; - NewExpression.prototype.hasEffectsWhenAccessedAtPath = function (path, _options) { - return path.length > 1; - }; - NewExpression.prototype.initialise = function () { - this.included = false; - this.callOptions = CallOptions.create({ - withNew: true, - args: this.arguments, - callIdentifier: this - }); - }; - return NewExpression; - }(NodeBase)); - - var SpreadElement$1 = /** @class */ (function (_super) { - __extends(SpreadElement, _super); - function SpreadElement() { - return _super !== null && _super.apply(this, arguments) || this; - } - SpreadElement.prototype.bind = function () { - _super.prototype.bind.call(this); - // Only properties of properties of the argument could become subject to reassignment - // This will also reassign the return values of iterators - this.argument.deoptimizePath([UNKNOWN_KEY, UNKNOWN_KEY]); - }; - return SpreadElement; - }(NodeBase)); - - var ObjectExpression$1 = /** @class */ (function (_super) { - __extends(ObjectExpression$$1, _super); - function ObjectExpression$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - ObjectExpression$$1.prototype.bind = function () { - _super.prototype.bind.call(this); - if (this.propertyMap === null) - this.buildPropertyMap(); - }; - // We could also track this per-property but this would quickly become much more complex - ObjectExpression$$1.prototype.deoptimizeCache = function () { - if (!this.hasUnknownDeoptimizedProperty) - this.deoptimizeAllProperties(); - }; - ObjectExpression$$1.prototype.getLiteralValueAtPath = function (path, recursionTracker, origin) { - if (this.propertyMap === null) - this.buildPropertyMap(); - var key = path[0]; - if (path.length === 0 || - this.hasUnknownDeoptimizedProperty || - typeof key !== 'string' || - this.deoptimizedPaths[key]) - return UNKNOWN_VALUE; - if (path.length === 1 && - !this.propertyMap[key] && - this.unmatchablePropertiesRead.length === 0) { - if (!this.expressionsToBeDeoptimized[key]) { - this.expressionsToBeDeoptimized[key] = [origin]; - } - else { - this.expressionsToBeDeoptimized[key].push(origin); - } - return undefined; - } - if (!this.propertyMap[key] || - this.propertyMap[key].exactMatchRead === null || - this.propertyMap[key].propertiesRead.length > 1) - return UNKNOWN_VALUE; - if (!this.expressionsToBeDeoptimized[key]) { - this.expressionsToBeDeoptimized[key] = [origin]; - } - else { - this.expressionsToBeDeoptimized[key].push(origin); - } - return this.propertyMap[key].exactMatchRead.getLiteralValueAtPath(path.slice(1), recursionTracker, origin); - }; - ObjectExpression$$1.prototype.getReturnExpressionWhenCalledAtPath = function (path, recursionTracker, origin) { - if (this.propertyMap === null) - this.buildPropertyMap(); - var key = path[0]; - if (path.length === 0 || - this.hasUnknownDeoptimizedProperty || - typeof key !== 'string' || - this.deoptimizedPaths[key]) - return UNKNOWN_EXPRESSION; - if (path.length === 1 && - objectMembers[key] && - this.unmatchablePropertiesRead.length === 0 && - (!this.propertyMap[key] || this.propertyMap[key].exactMatchRead === null)) - return getMemberReturnExpressionWhenCalled(objectMembers, key); - if (!this.propertyMap[key] || - this.propertyMap[key].exactMatchRead === null || - this.propertyMap[key].propertiesRead.length > 1) - return UNKNOWN_EXPRESSION; - if (!this.expressionsToBeDeoptimized[key]) { - this.expressionsToBeDeoptimized[key] = [origin]; - } - else { - this.expressionsToBeDeoptimized[key].push(origin); - } - return this.propertyMap[key].exactMatchRead.getReturnExpressionWhenCalledAtPath(path.slice(1), recursionTracker, origin); - }; - ObjectExpression$$1.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - if (path.length === 0) - return false; - var key = path[0]; - if (path.length > 1 && - (this.hasUnknownDeoptimizedProperty || - typeof key !== 'string' || - this.deoptimizedPaths[key] || - !this.propertyMap[key] || - this.propertyMap[key].exactMatchRead === null)) - return true; - var subPath = path.slice(1); - for (var _i = 0, _a = typeof key !== 'string' - ? this.properties - : this.propertyMap[key] - ? this.propertyMap[key].propertiesRead - : []; _i < _a.length; _i++) { - var property = _a[_i]; - if (property.hasEffectsWhenAccessedAtPath(subPath, options)) - return true; - } - return false; - }; - ObjectExpression$$1.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - if (path.length === 0) - return false; - var key = path[0]; - if (path.length > 1 && - (this.hasUnknownDeoptimizedProperty || - typeof key !== 'string' || - this.deoptimizedPaths[key] || - !this.propertyMap[key] || - this.propertyMap[key].exactMatchRead === null)) - return true; - var subPath = path.slice(1); - for (var _i = 0, _a = typeof key !== 'string' - ? this.properties - : path.length > 1 - ? this.propertyMap[key].propertiesRead - : this.propertyMap[key] - ? this.propertyMap[key].propertiesSet - : []; _i < _a.length; _i++) { - var property = _a[_i]; - if (property.hasEffectsWhenAssignedAtPath(subPath, options)) - return true; - } - return false; - }; - ObjectExpression$$1.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - var key = path[0]; - if (path.length === 0 || - this.hasUnknownDeoptimizedProperty || - typeof key !== 'string' || - this.deoptimizedPaths[key] || - (this.propertyMap[key] - ? !this.propertyMap[key].exactMatchRead - : path.length > 1 || !objectMembers[key])) - return true; - var subPath = path.slice(1); - for (var _i = 0, _a = this.propertyMap[key] ? this.propertyMap[key].propertiesRead : []; _i < _a.length; _i++) { - var property = _a[_i]; - if (property.hasEffectsWhenCalledAtPath(subPath, callOptions, options)) - return true; - } - if (path.length === 1 && objectMembers[key]) - return hasMemberEffectWhenCalled(objectMembers, key, this.included, callOptions, options); - return false; - }; - ObjectExpression$$1.prototype.initialise = function () { - this.included = false; - this.hasUnknownDeoptimizedProperty = false; - this.deoptimizedPaths = Object.create(null); - this.propertyMap = null; - this.expressionsToBeDeoptimized = Object.create(null); - }; - ObjectExpression$$1.prototype.deoptimizePath = function (path) { - if (this.hasUnknownDeoptimizedProperty) - return; - if (this.propertyMap === null) - this.buildPropertyMap(); - if (path.length === 0) { - this.deoptimizeAllProperties(); - return; - } - var key = path[0]; - if (path.length === 1) { - if (typeof key !== 'string') { - this.deoptimizeAllProperties(); - return; - } - if (!this.deoptimizedPaths[key]) { - this.deoptimizedPaths[key] = true; - // we only deoptimizeCache exact matches as in all other cases, - // we do not return a literal value or return expression - if (this.expressionsToBeDeoptimized[key]) { - for (var _i = 0, _a = this.expressionsToBeDeoptimized[key]; _i < _a.length; _i++) { - var expression = _a[_i]; - expression.deoptimizeCache(); - } - } - } - } - var subPath = path.length === 1 ? UNKNOWN_PATH : path.slice(1); - for (var _b = 0, _c = typeof key === 'string' - ? this.propertyMap[key] - ? this.propertyMap[key].propertiesRead - : [] - : this.properties; _b < _c.length; _b++) { - var property = _c[_b]; - property.deoptimizePath(subPath); - } - }; - ObjectExpression$$1.prototype.deoptimizeAllProperties = function () { - this.hasUnknownDeoptimizedProperty = true; - for (var _i = 0, _a = this.properties; _i < _a.length; _i++) { - var property = _a[_i]; - property.deoptimizePath(UNKNOWN_PATH); - } - for (var _b = 0, _c = Object.keys(this.expressionsToBeDeoptimized); _b < _c.length; _b++) { - var key = _c[_b]; - for (var _d = 0, _e = this.expressionsToBeDeoptimized[key]; _d < _e.length; _d++) { - var expression = _e[_d]; - expression.deoptimizeCache(); - } - } - }; - ObjectExpression$$1.prototype.render = function (code, options, _a) { - var renderedParentType = (_a === void 0 ? BLANK : _a).renderedParentType; - _super.prototype.render.call(this, code, options); - if (renderedParentType === ExpressionStatement) { - code.appendRight(this.start, '('); - code.prependLeft(this.end, ')'); - } - }; - ObjectExpression$$1.prototype.buildPropertyMap = function () { - var _a, _b; - this.propertyMap = Object.create(null); - this.unmatchablePropertiesRead = []; - this.unmatchablePropertiesWrite = []; - for (var index = this.properties.length - 1; index >= 0; index--) { - var property = this.properties[index]; - if (property instanceof SpreadElement$1) { - this.unmatchablePropertiesRead.push(property); - continue; - } - var isWrite = property.kind !== 'get'; - var isRead = property.kind !== 'set'; - var key = void 0; - if (property.computed) { - var keyValue = property.key.getLiteralValueAtPath(EMPTY_PATH, EMPTY_IMMUTABLE_TRACKER, this); - if (keyValue === UNKNOWN_VALUE) { - if (isRead) { - this.unmatchablePropertiesRead.push(property); - } - else { - this.unmatchablePropertiesWrite.push(property); - } - continue; - } - key = String(keyValue); - } - else if (property.key instanceof Identifier$1) { - key = property.key.name; - } - else { - key = String(property.key.value); - } - var propertyMapProperty = this.propertyMap[key]; - if (!propertyMapProperty) { - this.propertyMap[key] = { - exactMatchRead: isRead ? property : null, - propertiesRead: isRead ? [property].concat(this.unmatchablePropertiesRead) : [], - exactMatchWrite: isWrite ? property : null, - propertiesSet: isWrite && !isRead ? [property].concat(this.unmatchablePropertiesWrite) : [] - }; - continue; - } - if (isRead && propertyMapProperty.exactMatchRead === null) { - propertyMapProperty.exactMatchRead = property; - (_a = propertyMapProperty.propertiesRead).push.apply(_a, [property].concat(this.unmatchablePropertiesRead)); - } - if (isWrite && !isRead && propertyMapProperty.exactMatchWrite === null) { - propertyMapProperty.exactMatchWrite = property; - (_b = propertyMapProperty.propertiesSet).push.apply(_b, [property].concat(this.unmatchablePropertiesWrite)); - } - } - }; - return ObjectExpression$$1; - }(NodeBase)); - - var ObjectPattern$1 = /** @class */ (function (_super) { - __extends(ObjectPattern, _super); - function ObjectPattern() { - return _super !== null && _super.apply(this, arguments) || this; - } - ObjectPattern.prototype.declare = function (kind, init) { - for (var _i = 0, _a = this.properties; _i < _a.length; _i++) { - var property = _a[_i]; - property.declare(kind, init); - } - }; - ObjectPattern.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - if (path.length > 0) - return true; - for (var _i = 0, _a = this.properties; _i < _a.length; _i++) { - var property = _a[_i]; - if (property.hasEffectsWhenAssignedAtPath(EMPTY_PATH, options)) - return true; - } - return false; - }; - ObjectPattern.prototype.deoptimizePath = function (path) { - if (path.length === 0) { - for (var _i = 0, _a = this.properties; _i < _a.length; _i++) { - var property = _a[_i]; - property.deoptimizePath(path); - } - } - }; - return ObjectPattern; - }(NodeBase)); - - var Program$1 = /** @class */ (function (_super) { - __extends(Program, _super); - function Program() { - return _super !== null && _super.apply(this, arguments) || this; - } - Program.prototype.hasEffects = function (options) { - for (var _i = 0, _a = this.body; _i < _a.length; _i++) { - var node = _a[_i]; - if (node.hasEffects(options)) - return true; - } - }; - Program.prototype.include = function () { - this.included = true; - for (var _i = 0, _a = this.body; _i < _a.length; _i++) { - var node = _a[_i]; - if (node.shouldBeIncluded()) - node.include(); - } - }; - Program.prototype.render = function (code, options) { - if (this.body.length) { - renderStatementList(this.body, code, this.start, this.end, options); - } - else { - _super.prototype.render.call(this, code, options); - } - }; - return Program; - }(NodeBase)); - - var Property$1 = /** @class */ (function (_super) { - __extends(Property, _super); - function Property() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.declarationInit = null; - return _this; - } - Property.prototype.bind = function () { - _super.prototype.bind.call(this); - if (this.kind === 'get' && this.returnExpression === null) - this.updateReturnExpression(); - if (this.declarationInit !== null) { - this.declarationInit.deoptimizePath([UNKNOWN_KEY, UNKNOWN_KEY]); - } - }; - Property.prototype.declare = function (kind, init) { - this.declarationInit = init; - this.value.declare(kind, UNKNOWN_EXPRESSION); - }; - Property.prototype.deoptimizeCache = function () { - // As getter properties directly receive their values from function expressions that always - // have a fixed return value, there is no known situation where a getter is deoptimized. - throw new Error('Unexpected deoptimization'); - }; - Property.prototype.getLiteralValueAtPath = function (path, recursionTracker, origin) { - if (this.kind === 'set') { - return UNKNOWN_VALUE; - } - if (this.kind === 'get') { - if (this.returnExpression === null) - this.updateReturnExpression(); - return this.returnExpression.getLiteralValueAtPath(path, recursionTracker, origin); - } - return this.value.getLiteralValueAtPath(path, recursionTracker, origin); - }; - Property.prototype.getReturnExpressionWhenCalledAtPath = function (path, recursionTracker, origin) { - if (this.kind === 'set') { - return UNKNOWN_EXPRESSION; - } - if (this.kind === 'get') { - if (this.returnExpression === null) - this.updateReturnExpression(); - return this.returnExpression.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin); - } - return this.value.getReturnExpressionWhenCalledAtPath(path, recursionTracker, origin); - }; - Property.prototype.hasEffects = function (options) { - return this.key.hasEffects(options) || this.value.hasEffects(options); - }; - Property.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - if (this.kind === 'get') { - return (this.value.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.accessorCallOptions, options.getHasEffectsWhenCalledOptions()) || - (path.length > 0 && this.returnExpression.hasEffectsWhenAccessedAtPath(path, options))); - } - return this.value.hasEffectsWhenAccessedAtPath(path, options); - }; - Property.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - if (this.kind === 'get') { - return path.length === 0 || this.returnExpression.hasEffectsWhenAssignedAtPath(path, options); - } - if (this.kind === 'set') { - return (path.length > 0 || - this.value.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.accessorCallOptions, options.getHasEffectsWhenCalledOptions())); - } - return this.value.hasEffectsWhenAssignedAtPath(path, options); - }; - Property.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - if (this.kind === 'get') { - return this.returnExpression.hasEffectsWhenCalledAtPath(path, callOptions, options); - } - return this.value.hasEffectsWhenCalledAtPath(path, callOptions, options); - }; - Property.prototype.initialise = function () { - this.included = false; - this.returnExpression = null; - this.accessorCallOptions = CallOptions.create({ - withNew: false, - callIdentifier: this - }); - }; - Property.prototype.deoptimizePath = function (path) { - if (this.kind === 'get') { - if (path.length > 0) { - if (this.returnExpression === null) - this.updateReturnExpression(); - this.returnExpression.deoptimizePath(path); - } - } - else if (this.kind !== 'set') { - this.value.deoptimizePath(path); - } - }; - Property.prototype.render = function (code, options) { - if (!this.shorthand) { - this.key.render(code, options); - } - this.value.render(code, options); - }; - Property.prototype.updateReturnExpression = function () { - this.returnExpression = UNKNOWN_EXPRESSION; - this.returnExpression = this.value.getReturnExpressionWhenCalledAtPath(EMPTY_PATH, EMPTY_IMMUTABLE_TRACKER, this); - }; - return Property; - }(NodeBase)); - - var RestElement$1 = /** @class */ (function (_super) { - __extends(RestElement, _super); - function RestElement() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.declarationInit = null; - return _this; - } - RestElement.prototype.bind = function () { - _super.prototype.bind.call(this); - if (this.declarationInit !== null) { - this.declarationInit.deoptimizePath([UNKNOWN_KEY, UNKNOWN_KEY]); - } - }; - RestElement.prototype.declare = function (kind, init) { - this.argument.declare(kind, UNKNOWN_EXPRESSION); - this.declarationInit = init; - }; - RestElement.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - return path.length > 0 || this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, options); - }; - RestElement.prototype.deoptimizePath = function (path) { - path.length === 0 && this.argument.deoptimizePath(EMPTY_PATH); - }; - return RestElement; - }(NodeBase)); - - var ReturnStatement$1 = /** @class */ (function (_super) { - __extends(ReturnStatement, _super); - function ReturnStatement() { - return _super !== null && _super.apply(this, arguments) || this; - } - ReturnStatement.prototype.hasEffects = function (options) { - return (!options.ignoreReturnAwaitYield() || (this.argument && this.argument.hasEffects(options))); - }; - ReturnStatement.prototype.initialise = function () { - this.included = false; - this.scope.addReturnExpression(this.argument || UNKNOWN_EXPRESSION); - }; - ReturnStatement.prototype.render = function (code, options) { - if (this.argument) { - this.argument.render(code, options); - if (this.argument.start === this.start + 6 /* 'return'.length */) { - code.prependLeft(this.start + 6, ' '); - } - } - }; - return ReturnStatement; - }(NodeBase)); - - var SequenceExpression$1 = /** @class */ (function (_super) { - __extends(SequenceExpression, _super); - function SequenceExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - SequenceExpression.prototype.getLiteralValueAtPath = function (path, recursionTracker, origin) { - return this.expressions[this.expressions.length - 1].getLiteralValueAtPath(path, recursionTracker, origin); - }; - SequenceExpression.prototype.hasEffects = function (options) { - for (var _i = 0, _a = this.expressions; _i < _a.length; _i++) { - var expression = _a[_i]; - if (expression.hasEffects(options)) - return true; - } - return false; - }; - SequenceExpression.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - return (path.length > 0 && - this.expressions[this.expressions.length - 1].hasEffectsWhenAccessedAtPath(path, options)); - }; - SequenceExpression.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - return (path.length === 0 || - this.expressions[this.expressions.length - 1].hasEffectsWhenAssignedAtPath(path, options)); - }; - SequenceExpression.prototype.hasEffectsWhenCalledAtPath = function (path, callOptions, options) { - return this.expressions[this.expressions.length - 1].hasEffectsWhenCalledAtPath(path, callOptions, options); - }; - SequenceExpression.prototype.include = function () { - this.included = true; - for (var i = 0; i < this.expressions.length - 1; i++) { - var node = this.expressions[i]; - if (node.shouldBeIncluded()) - node.include(); - } - this.expressions[this.expressions.length - 1].include(); - }; - SequenceExpression.prototype.deoptimizePath = function (path) { - if (path.length > 0) - this.expressions[this.expressions.length - 1].deoptimizePath(path); - }; - SequenceExpression.prototype.render = function (code, options, _a) { - var _b = _a === void 0 ? BLANK : _a, renderedParentType = _b.renderedParentType, isCalleeOfRenderedParent = _b.isCalleeOfRenderedParent; - var firstStart = 0, lastEnd, includedNodes = 0; - for (var _i = 0, _c = getCommaSeparatedNodesWithBoundaries(this.expressions, code, this.start, this.end); _i < _c.length; _i++) { - var _d = _c[_i], node = _d.node, start = _d.start, end = _d.end; - if (!node.included) { - code.remove(start, end); - continue; - } - includedNodes++; - if (firstStart === 0) - firstStart = start; - lastEnd = end; - if (node === this.expressions[this.expressions.length - 1] && includedNodes === 1) { - node.render(code, options, { - renderedParentType: renderedParentType || this.parent.type, - isCalleeOfRenderedParent: renderedParentType - ? isCalleeOfRenderedParent - : this.parent.callee === this - }); - } - else { - node.render(code, options); - } - } - // Round brackets are part of the actual parent and should be re-added in case the parent changed - if (includedNodes > 1 && renderedParentType) { - code.prependRight(firstStart, '('); - code.appendLeft(lastEnd, ')'); - } - }; - return SequenceExpression; - }(NodeBase)); - - var SwitchCase$1 = /** @class */ (function (_super) { - __extends(SwitchCase, _super); - function SwitchCase() { - return _super !== null && _super.apply(this, arguments) || this; - } - SwitchCase.prototype.include = function () { - this.included = true; - if (this.test) - this.test.include(); - for (var _i = 0, _a = this.consequent; _i < _a.length; _i++) { - var node = _a[_i]; - if (node.shouldBeIncluded()) - node.include(); - } - }; - SwitchCase.prototype.render = function (code, options) { - if (this.consequent.length) { - this.test && this.test.render(code, options); - var testEnd = this.test - ? this.test.end - : findFirstOccurrenceOutsideComment(code.original, 'default', this.start) + 7; - var consequentStart = findFirstOccurrenceOutsideComment(code.original, ':', testEnd) + 1; - renderStatementList(this.consequent, code, consequentStart, this.end, options); - } - else { - _super.prototype.render.call(this, code, options); - } - }; - return SwitchCase; - }(NodeBase)); - - var SwitchStatement$1 = /** @class */ (function (_super) { - __extends(SwitchStatement, _super); - function SwitchStatement() { - return _super !== null && _super.apply(this, arguments) || this; - } - SwitchStatement.prototype.createScope = function (parentScope) { - this.scope = new BlockScope(parentScope); - }; - SwitchStatement.prototype.hasEffects = function (options) { - return _super.prototype.hasEffects.call(this, options.setIgnoreBreakStatements()); - }; - return SwitchStatement; - }(NodeBase)); - - var TaggedTemplateExpression$1 = /** @class */ (function (_super) { - __extends(TaggedTemplateExpression$$1, _super); - function TaggedTemplateExpression$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - TaggedTemplateExpression$$1.prototype.bind = function () { - _super.prototype.bind.call(this); - if (this.tag.type === Identifier) { - var variable = this.scope.findVariable(this.tag.name); - if (variable.isNamespace) { - this.context.error({ - code: 'CANNOT_CALL_NAMESPACE', - message: "Cannot call a namespace ('" + this.tag.name + "')" - }, this.start); - } - if (this.tag.name === 'eval') { - this.context.warn({ - code: 'EVAL', - message: "Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification", - url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval' - }, this.start); - } - } - }; - TaggedTemplateExpression$$1.prototype.hasEffects = function (options) { - return (_super.prototype.hasEffects.call(this, options) || - this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, options.getHasEffectsWhenCalledOptions())); - }; - TaggedTemplateExpression$$1.prototype.initialise = function () { - this.included = false; - this.callOptions = CallOptions.create({ - withNew: false, - callIdentifier: this - }); - }; - return TaggedTemplateExpression$$1; - }(NodeBase)); - - var TemplateElement$1 = /** @class */ (function (_super) { - __extends(TemplateElement, _super); - function TemplateElement() { - return _super !== null && _super.apply(this, arguments) || this; - } - TemplateElement.prototype.hasEffects = function (_options) { - return false; - }; - return TemplateElement; - }(NodeBase)); - - function isTemplateLiteral(node) { - return node.type === TemplateLiteral; - } - var TemplateLiteral$1 = /** @class */ (function (_super) { - __extends(TemplateLiteral$$1, _super); - function TemplateLiteral$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - TemplateLiteral$$1.prototype.getLiteralValueAtPath = function (path) { - if (path.length > 0 || this.quasis.length !== 1) { - return UNKNOWN_VALUE; - } - return this.quasis[0].value.cooked; - }; - TemplateLiteral$$1.prototype.render = function (code, options) { - code.indentExclusionRanges.push([this.start, this.end]); - _super.prototype.render.call(this, code, options); - }; - return TemplateLiteral$$1; - }(NodeBase)); - - var ThisExpression$1 = /** @class */ (function (_super) { - __extends(ThisExpression, _super); - function ThisExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - ThisExpression.prototype.bind = function () { - _super.prototype.bind.call(this); - this.variable = this.scope.findVariable('this'); - }; - ThisExpression.prototype.hasEffectsWhenAccessedAtPath = function (path, options) { - return path.length > 0 && this.variable.hasEffectsWhenAccessedAtPath(path, options); - }; - ThisExpression.prototype.hasEffectsWhenAssignedAtPath = function (path, options) { - return this.variable.hasEffectsWhenAssignedAtPath(path, options); - }; - ThisExpression.prototype.initialise = function () { - this.included = false; - this.variable = null; - this.alias = this.scope.findLexicalBoundary().isModuleScope ? this.context.moduleContext : null; - if (this.alias === 'undefined') { - this.context.warn({ - code: 'THIS_IS_UNDEFINED', - message: "The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten", - url: "https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined" - }, this.start); - } - }; - ThisExpression.prototype.render = function (code, _options) { - if (this.alias !== null) { - code.overwrite(this.start, this.end, this.alias, { - storeName: true, - contentOnly: false - }); - } - }; - return ThisExpression; - }(NodeBase)); - - var ThrowStatement$1 = /** @class */ (function (_super) { - __extends(ThrowStatement, _super); - function ThrowStatement() { - return _super !== null && _super.apply(this, arguments) || this; - } - ThrowStatement.prototype.hasEffects = function (_options) { - return true; - }; - return ThrowStatement; - }(NodeBase)); - - var unaryOperators = { - '-': function (value) { return -value; }, - '+': function (value) { return +value; }, - '!': function (value) { return !value; }, - '~': function (value) { return ~value; }, - typeof: function (value) { return typeof value; }, - void: function () { return undefined; }, - delete: function () { return UNKNOWN_VALUE; } - }; - var UnaryExpression$1 = /** @class */ (function (_super) { - __extends(UnaryExpression, _super); - function UnaryExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - UnaryExpression.prototype.bind = function () { - _super.prototype.bind.call(this); - if (this.operator === 'delete') { - this.argument.deoptimizePath(EMPTY_PATH); - } - }; - UnaryExpression.prototype.getLiteralValueAtPath = function (path, recursionTracker, origin) { - if (path.length > 0) - return UNKNOWN_VALUE; - var argumentValue = this.argument.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin); - if (argumentValue === UNKNOWN_VALUE) - return UNKNOWN_VALUE; - return unaryOperators[this.operator](argumentValue); - }; - UnaryExpression.prototype.hasEffects = function (options) { - return (this.argument.hasEffects(options) || - (this.operator === 'delete' && - this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, options))); - }; - UnaryExpression.prototype.hasEffectsWhenAccessedAtPath = function (path, _options) { - if (this.operator === 'void') { - return path.length > 0; - } - return path.length > 1; - }; - return UnaryExpression; - }(NodeBase)); - - var UnknownNode = /** @class */ (function (_super) { - __extends(UnknownNode, _super); - function UnknownNode() { - return _super !== null && _super.apply(this, arguments) || this; - } - UnknownNode.prototype.hasEffects = function (_options) { - return true; - }; - return UnknownNode; - }(NodeBase)); - - var UpdateExpression$1 = /** @class */ (function (_super) { - __extends(UpdateExpression, _super); - function UpdateExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - UpdateExpression.prototype.bind = function () { - _super.prototype.bind.call(this); - this.argument.deoptimizePath(EMPTY_PATH); - if (isIdentifier(this.argument)) { - var variable = this.scope.findVariable(this.argument.name); - variable.isReassigned = true; - } - }; - UpdateExpression.prototype.hasEffects = function (options) { - return (this.argument.hasEffects(options) || - this.argument.hasEffectsWhenAssignedAtPath(EMPTY_PATH, options)); - }; - UpdateExpression.prototype.hasEffectsWhenAccessedAtPath = function (path, _options) { - return path.length > 1; - }; - return UpdateExpression; - }(NodeBase)); - - function isReassignedExportsMember(variable) { - return (variable.safeName && - variable.safeName.indexOf('.') !== -1 && - variable.exportName && - variable.isReassigned); - } - var VariableDeclaration$1 = /** @class */ (function (_super) { - __extends(VariableDeclaration$$1, _super); - function VariableDeclaration$$1() { - return _super !== null && _super.apply(this, arguments) || this; - } - VariableDeclaration$$1.prototype.hasEffectsWhenAssignedAtPath = function (_path, _options) { - return false; - }; - VariableDeclaration$$1.prototype.includeWithAllDeclaredVariables = function () { - var anotherPassNeeded = false; - this.included = true; - for (var _i = 0, _a = this.declarations; _i < _a.length; _i++) { - var declarator = _a[_i]; - if (declarator.include()) - anotherPassNeeded = true; - } - return anotherPassNeeded; - }; - VariableDeclaration$$1.prototype.include = function () { - this.included = true; - for (var _i = 0, _a = this.declarations; _i < _a.length; _i++) { - var declarator = _a[_i]; - if (declarator.shouldBeIncluded()) - declarator.include(); - } - }; - VariableDeclaration$$1.prototype.initialise = function () { - this.included = false; - for (var _i = 0, _a = this.declarations; _i < _a.length; _i++) { - var declarator = _a[_i]; - declarator.declareDeclarator(this.kind); - } - }; - VariableDeclaration$$1.prototype.deoptimizePath = function (_path) { - for (var _i = 0, _a = this.declarations; _i < _a.length; _i++) { - var declarator = _a[_i]; - declarator.deoptimizePath(EMPTY_PATH); - } - }; - VariableDeclaration$$1.prototype.render = function (code, options, nodeRenderOptions) { - if (nodeRenderOptions === void 0) { nodeRenderOptions = BLANK; } - if (this.declarations.every(function (declarator) { - return declarator.included && (!declarator.id.variable || !declarator.id.variable.exportName); - })) { - for (var _i = 0, _a = this.declarations; _i < _a.length; _i++) { - var declarator = _a[_i]; - declarator.render(code, options); - } - if (!nodeRenderOptions.isNoStatement && - code.original.charCodeAt(this.end - 1) !== 59 /*";"*/) { - code.appendLeft(this.end, ';'); - } - } - else { - this.renderReplacedDeclarations(code, options, nodeRenderOptions); - } - }; - VariableDeclaration$$1.prototype.renderReplacedDeclarations = function (code, options, _a) { - var _b = _a.start, start = _b === void 0 ? this.start : _b, _c = _a.end, end = _c === void 0 ? this.end : _c, isNoStatement = _a.isNoStatement; - var separatedNodes = getCommaSeparatedNodesWithBoundaries(this.declarations, code, this.start + this.kind.length, this.end - (code.original.charCodeAt(this.end - 1) === 59 /*";"*/ ? 1 : 0)); - var actualContentEnd, renderedContentEnd; - if (/\n\s*$/.test(code.slice(this.start, separatedNodes[0].start))) { - renderedContentEnd = this.start + this.kind.length; - } - else { - renderedContentEnd = separatedNodes[0].start; - } - var lastSeparatorPos = renderedContentEnd - 1; - code.remove(this.start, lastSeparatorPos); - var isInDeclaration = false; - var hasRenderedContent = false; - var separatorString = '', leadingString, nextSeparatorString; - for (var _i = 0, separatedNodes_1 = separatedNodes; _i < separatedNodes_1.length; _i++) { - var _d = separatedNodes_1[_i], node = _d.node, start_1 = _d.start, separator = _d.separator, contentEnd = _d.contentEnd, end_1 = _d.end; - if (!node.included || - (isIdentifier(node.id) && isReassignedExportsMember(node.id.variable) && node.init === null)) { - code.remove(start_1, end_1); - continue; - } - leadingString = ''; - nextSeparatorString = ''; - if (isIdentifier(node.id) && isReassignedExportsMember(node.id.variable)) { - if (hasRenderedContent) { - separatorString += ';'; - } - isInDeclaration = false; - } - else { - if (options.format === 'system' && - node.init !== null && - isIdentifier(node.id) && - node.id.variable.exportName) { - code.prependLeft(node.init.start, "exports('" + (node.id.variable.safeExportName || node.id.variable.exportName) + "', "); - nextSeparatorString += ')'; - } - if (isInDeclaration) { - separatorString += ','; - } - else { - if (hasRenderedContent) { - separatorString += ';'; - } - leadingString += this.kind + " "; - isInDeclaration = true; - } - } - if (renderedContentEnd === lastSeparatorPos + 1) { - code.overwrite(lastSeparatorPos, renderedContentEnd, separatorString + leadingString); - } - else { - code.overwrite(lastSeparatorPos, lastSeparatorPos + 1, separatorString); - code.appendLeft(renderedContentEnd, leadingString); - } - node.render(code, options); - actualContentEnd = contentEnd; - renderedContentEnd = end_1; - hasRenderedContent = true; - lastSeparatorPos = separator; - separatorString = nextSeparatorString; - } - if (hasRenderedContent) { - this.renderDeclarationEnd(code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, !isNoStatement); - } - else { - code.remove(start, end); - } - }; - VariableDeclaration$$1.prototype.renderDeclarationEnd = function (code, separatorString, lastSeparatorPos, actualContentEnd, renderedContentEnd, addSemicolon) { - if (code.original.charCodeAt(this.end - 1) === 59 /*";"*/) { - code.remove(this.end - 1, this.end); - } - if (addSemicolon) { - separatorString += ';'; - } - if (lastSeparatorPos !== null) { - if (code.original.charCodeAt(actualContentEnd - 1) === 10 /*"\n"*/ && - (code.original.charCodeAt(this.end) === 10 /*"\n"*/ || - code.original.charCodeAt(this.end) === 13) /*"\r"*/) { - actualContentEnd--; - if (code.original.charCodeAt(actualContentEnd) === 13 /*"\r"*/) { - actualContentEnd--; - } - } - if (actualContentEnd === lastSeparatorPos + 1) { - code.overwrite(lastSeparatorPos, renderedContentEnd, separatorString); - } - else { - code.overwrite(lastSeparatorPos, lastSeparatorPos + 1, separatorString); - code.remove(actualContentEnd, renderedContentEnd); - } - } - else { - code.appendLeft(renderedContentEnd, separatorString); - } - return separatorString; - }; - return VariableDeclaration$$1; - }(NodeBase)); - - var VariableDeclarator$1 = /** @class */ (function (_super) { - __extends(VariableDeclarator, _super); - function VariableDeclarator() { - return _super !== null && _super.apply(this, arguments) || this; - } - VariableDeclarator.prototype.declareDeclarator = function (kind) { - this.id.declare(kind, this.init || UNDEFINED_EXPRESSION); - }; - VariableDeclarator.prototype.deoptimizePath = function (path) { - this.id.deoptimizePath(path); - }; - return VariableDeclarator; - }(NodeBase)); - - var WhileStatement$1 = /** @class */ (function (_super) { - __extends(WhileStatement, _super); - function WhileStatement() { - return _super !== null && _super.apply(this, arguments) || this; - } - WhileStatement.prototype.hasEffects = function (options) { - return (this.test.hasEffects(options) || this.body.hasEffects(options.setIgnoreBreakStatements())); - }; - return WhileStatement; - }(NodeBase)); - - var YieldExpression$1 = /** @class */ (function (_super) { - __extends(YieldExpression, _super); - function YieldExpression() { - return _super !== null && _super.apply(this, arguments) || this; - } - YieldExpression.prototype.bind = function () { - _super.prototype.bind.call(this); - if (this.argument !== null) { - this.argument.deoptimizePath(UNKNOWN_PATH); - } - }; - YieldExpression.prototype.hasEffects = function (options) { - return (!options.ignoreReturnAwaitYield() || (this.argument && this.argument.hasEffects(options))); - }; - YieldExpression.prototype.render = function (code, options) { - if (this.argument) { - this.argument.render(code, options); - if (this.argument.start === this.start + 5 /* 'yield'.length */) { - code.prependLeft(this.start + 5, ' '); - } - } - }; - return YieldExpression; - }(NodeBase)); - - var nodeConstructors = { - ArrayExpression: ArrayExpression$1, - ArrayPattern: ArrayPattern$1, - ArrowFunctionExpression: ArrowFunctionExpression$1, - AssignmentExpression: AssignmentExpression$1, - AssignmentPattern: AssignmentPattern$1, - AwaitExpression: AwaitExpression$1, - BinaryExpression: BinaryExpression$1, - BlockStatement: BlockStatement$1, - BreakStatement: BreakStatement$1, - CallExpression: CallExpression$1, - CatchClause: CatchClause$1, - ClassBody: ClassBody$1, - ClassDeclaration: ClassDeclaration$1, - ClassExpression: ClassExpression$1, - ConditionalExpression: ConditionalExpression$1, - DoWhileStatement: DoWhileStatement$1, - EmptyStatement: EmptyStatement$1, - ExportAllDeclaration: ExportAllDeclaration$1, - ExportDefaultDeclaration: ExportDefaultDeclaration$1, - ExportNamedDeclaration: ExportNamedDeclaration$1, - ExpressionStatement: ExpressionStatement$1, - ForStatement: ForStatement$1, - ForInStatement: ForInStatement$1, - ForOfStatement: ForOfStatement$1, - FunctionDeclaration: FunctionDeclaration$1, - FunctionExpression: FunctionExpression$1, - Identifier: Identifier$1, - IfStatement: IfStatement$1, - Import: Import$1, - ImportDeclaration: ImportDeclaration$1, - LabeledStatement: LabeledStatement$1, - Literal: Literal$1, - LogicalExpression: LogicalExpression$1, - MemberExpression: MemberExpression$1, - MetaProperty: MetaProperty$1, - MethodDefinition: MethodDefinition$1, - NewExpression: NewExpression$1, - ObjectExpression: ObjectExpression$1, - ObjectPattern: ObjectPattern$1, - Program: Program$1, - Property: Property$1, - RestElement: RestElement$1, - ReturnStatement: ReturnStatement$1, - SequenceExpression: SequenceExpression$1, - SpreadElement: SpreadElement$1, - SwitchCase: SwitchCase$1, - SwitchStatement: SwitchStatement$1, - TaggedTemplateExpression: TaggedTemplateExpression$1, - TemplateElement: TemplateElement$1, - TemplateLiteral: TemplateLiteral$1, - ThisExpression: ThisExpression$1, - ThrowStatement: ThrowStatement$1, - TryStatement: NodeBase, - UnaryExpression: UnaryExpression$1, - UnknownNode: UnknownNode, - UpdateExpression: UpdateExpression$1, - VariableDeclarator: VariableDeclarator$1, - VariableDeclaration: VariableDeclaration$1, - WhileStatement: WhileStatement$1, - YieldExpression: YieldExpression$1 - }; - - var addDeclaredNames = function (variable, names) { - if (variable.isNamespace && !variable.isExternal) { - for (var _i = 0, _a = variable.context.getExports(); _i < _a.length; _i++) { - var name = _a[_i]; - addDeclaredNames(variable.context.traceExport(name), names); - } - } - names.add(variable.getName()); - }; - var ModuleScope = /** @class */ (function (_super) { - __extends(ModuleScope, _super); - function ModuleScope(parent, context) { - var _this = _super.call(this, parent) || this; - _this.context = context; - _this.isModuleScope = true; - _this.variables.this = new LocalVariable('this', null, UNDEFINED_EXPRESSION, context.deoptimizationTracker); - return _this; - } - ModuleScope.prototype.deshadow = function (names, children) { - if (children === void 0) { children = this.children; } - var localNames = new Set(names); - for (var _i = 0, _a = Object.keys(this.context.imports); _i < _a.length; _i++) { - var importName = _a[_i]; - var importDescription = this.context.imports[importName]; - if (importDescription.module.isExternal || this.context.isCrossChunkImport(importDescription)) - continue; - for (var _b = 0, _c = importDescription.module.getAllExports(); _b < _c.length; _b++) { - var name = _c[_b]; - addDeclaredNames(importDescription.module.traceExport(name), localNames); - } - if (importDescription.name !== '*') { - var declaration = importDescription.module.traceExport(importDescription.name); - if (!declaration) { - this.context.warn({ - code: 'NON_EXISTENT_EXPORT', - name: importDescription.name, - source: importDescription.module.id, - message: "Non-existent export '" + importDescription.name + "' is imported from " + relativeId(importDescription.module.id) - }, importDescription.start); - continue; - } - var name = declaration.getName(); - if (name !== importDescription.name) - localNames.add(name); - if (importDescription.name !== 'default' && importDescription.name !== importName) - localNames.add(importDescription.name); - } - } - _super.prototype.deshadow.call(this, localNames, children); - }; - ModuleScope.prototype.findLexicalBoundary = function () { - return this; - }; - ModuleScope.prototype.findVariable = function (name) { - if (this.variables[name]) { - return this.variables[name]; - } - return this.context.traceVariable(name) || this.parent.findVariable(name); - }; - return ModuleScope; - }(Scope)); - - function extractNames(param) { - var names = []; - extractors[param.type](names, param); - return names; - } - var extractors = { - Identifier: function (names, param) { - names.push(param.name); - }, - ObjectPattern: function (names, param) { - param.properties.forEach(function (prop) { - if (prop instanceof RestElement$1) { - extractors[prop.argument.type](names, prop.argument); - } - else { - extractors[prop.value.type](names, prop.value); - } - }); - }, - ArrayPattern: function (names, param) { - param.elements.forEach(function (element) { - if (element) - extractors[element.type](names, element); - }); - }, - RestElement: function (names, param) { - extractors[param.argument.type](names, param.argument); - }, - AssignmentPattern: function (names, param) { - extractors[param.left.type](names, param.left); - } - }; - - var NamespaceVariable = /** @class */ (function (_super) { - __extends(NamespaceVariable, _super); - function NamespaceVariable(context) { - var _this = _super.call(this, context.getModuleName()) || this; - // Not initialised during construction - _this.originals = Object.create(null); - _this.needsNamespaceBlock = false; - _this.referencedEarly = false; - _this.references = []; - _this.context = context; - for (var _i = 0, _a = _this.context.getExports().concat(_this.context.getReexports()); _i < _a.length; _i++) { - var name = _a[_i]; - _this.originals[name] = _this.context.traceExport(name); - } - return _this; - } - NamespaceVariable.prototype.addReference = function (identifier) { - this.references.push(identifier); - this.name = identifier.name; - }; - NamespaceVariable.prototype.include = function () { - if (!this.included) { - this.context.includeNamespace(); - this.included = true; - this.needsNamespaceBlock = true; - for (var _i = 0, _a = this.references; _i < _a.length; _i++) { - var identifier = _a[_i]; - if (identifier.context.getModuleExecIndex() <= this.context.getModuleExecIndex()) { - this.referencedEarly = true; - break; - } - } - for (var _b = 0, _c = Object.keys(this.originals); _b < _c.length; _b++) { - var original = _c[_b]; - this.originals[original].include(); - } - } - }; - NamespaceVariable.prototype.renderFirst = function () { - return this.referencedEarly; - }; - // This is only called if "UNKNOWN_PATH" is reassigned as in all other situations, either the - // build fails due to an illegal namespace reassignment or MemberExpression already forwards - // the reassignment to the right variable. This means we lost track of this variable and thus - // need to reassign all exports. - NamespaceVariable.prototype.deoptimizePath = function () { - for (var key in this.originals) { - this.originals[key].deoptimizePath(UNKNOWN_PATH); - } - }; - NamespaceVariable.prototype.renderBlock = function (options) { - var _this = this; - var _ = options.compact ? '' : ' '; - var n = options.compact ? '' : '\n'; - var t = options.indent; - var members = Object.keys(this.originals).map(function (name) { - var original = _this.originals[name]; - if (_this.referencedEarly || original.isReassigned) { - return t + "get " + name + _ + "()" + _ + "{" + _ + "return " + original.getName() + (options.compact ? '' : ';') + _ + "}"; - } - return "" + t + name + ": " + original.getName(); - }); - var name = this.getName(); - var callee = options.freeze ? "/*#__PURE__*/Object.freeze" : ''; - var output = this.context.varOrConst + " " + name + " = " + (options.namespaceToStringTag - ? "{" + n + members.join("," + n) + n + "};" - : callee + "({" + n + members.join("," + n) + n + "});"); - if (options.namespaceToStringTag) { - output += n + "if" + _ + "(typeof Symbol" + _ + "!==" + _ + "'undefined'" + _ + "&&" + _ + "Symbol.toStringTag)" + n; - output += t + "Object.defineProperty(" + name + "," + _ + "Symbol.toStringTag," + _ + "{" + _ + "value:" + _ + "'Module'" + _ + "});" + n; - output += "else" + (n || ' '); - output += t + "Object.defineProperty(" + name + "," + _ + "'toString'," + _ + "{" + _ + "value:" + _ + "function" + _ + "()" + _ + "{" + _ + "return" + _ + "'[object Module]'" + (options.compact ? ';' : '') + _ + "}" + _ + "});" + n; - output += callee + "(" + name + ");"; - } - if (options.format === 'system' && this.exportName) { - output += n + "exports('" + this.exportName + "'," + _ + name + ");"; - } - return output; - }; - return NamespaceVariable; - }(Variable)); - NamespaceVariable.prototype.isNamespace = true; - - var nope = function (method) { return "Cannot use fs." + method + " inside browser"; }; - var lstatSync = nope('lstatSync'); - var readdirSync = nope('readdirSync'); - var readFileSync = nope('readFileSync'); - var realpathSync = nope('realpathSync'); - var writeFile = nope('writeFile'); - - function load(id) { - return readFileSync(id, 'utf-8'); - } - function findFile(file, preserveSymlinks) { - try { - var stats = lstatSync(file); - if (!preserveSymlinks && stats.isSymbolicLink()) - return findFile(realpathSync(file), preserveSymlinks); - if ((preserveSymlinks && stats.isSymbolicLink()) || stats.isFile()) { - // check case - var name = basename(file); - var files = readdirSync(dirname(file)); - if (files.indexOf(name) !== -1) - return file; - } - } - catch (err) { - // suppress - } - } - function addJsExtensionIfNecessary(file, preserveSymlinks) { - var found = findFile(file, preserveSymlinks); - if (found) - return found; - found = findFile(file + '.mjs', preserveSymlinks); - if (found) - return found; - found = findFile(file + '.js', preserveSymlinks); - return found; - } - function resolveId(options) { - return function (importee, importer) { - if (typeof process === 'undefined') { - error({ - code: 'MISSING_PROCESS', - message: "It looks like you're using Rollup in a non-Node.js environment. This means you must supply a plugin with custom resolveId and load functions", - url: 'https://github.com/rollup/rollup/wiki/Plugins' - }); - } - // external modules (non-entry modules that start with neither '.' or '/') - // are skipped at this stage. - if (importer !== undefined && !isAbsolute(importee) && importee[0] !== '.') - return null; - // `resolve` processes paths from right to left, prepending them until an - // absolute path is created. Absolute importees therefore shortcircuit the - // resolve call and require no special handing on our part. - // See https://nodejs.org/api/path.html#path_path_resolve_paths - return addJsExtensionIfNecessary(resolve(importer ? dirname(importer) : resolve(), importee), options.preserveSymlinks); - }; - } - function makeOnwarn() { - var warned = Object.create(null); - return function (warning) { - var str = warning.toString(); - if (str in warned) - return; - console.error(str); //eslint-disable-line no-console - warned[str] = true; - }; - } - function handleMissingExport(exportName, importingModule, importedModule, importerStart) { - importingModule.error({ - code: 'MISSING_EXPORT', - message: "'" + exportName + "' is not exported by " + relativeId(importedModule), - url: "https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module" - }, importerStart); - } - - function spaces(i) { - var result = ''; - while (i--) - result += ' '; - return result; - } - function tabsToSpaces(str) { - return str.replace(/^\t+/, function (match) { return match.split('\t').join(' '); }); - } - function getCodeFrame(source, line, column) { - var lines = source.split('\n'); - var frameStart = Math.max(0, line - 3); - var frameEnd = Math.min(line + 2, lines.length); - lines = lines.slice(frameStart, frameEnd); - while (!/\S/.test(lines[lines.length - 1])) { - lines.pop(); - frameEnd -= 1; - } - var digits = String(frameEnd).length; - return lines - .map(function (str, i) { - var isErrorLine = frameStart + i + 1 === line; - var lineNum = String(i + frameStart + 1); - while (lineNum.length < digits) - lineNum = " " + lineNum; - if (isErrorLine) { - var indicator = spaces(digits + 2 + tabsToSpaces(str.slice(0, column)).length) + '^'; - return lineNum + ": " + tabsToSpaces(str) + "\n" + indicator; - } - return lineNum + ": " + tabsToSpaces(str); - }) - .join('\n'); - } - - function getOriginalLocation(sourcemapChain, location) { - var filteredSourcemapChain = sourcemapChain.filter(function (sourcemap) { return sourcemap.mappings; }); - while (filteredSourcemapChain.length > 0) { - var sourcemap = filteredSourcemapChain.pop(); - var line = sourcemap.mappings[location.line - 1]; - var locationFound = false; - if (line !== undefined) { - for (var _i = 0, line_1 = line; _i < line_1.length; _i++) { - var segment = line_1[_i]; - if (segment[0] >= location.column) { - if (segment.length < 4) - break; - location = { - line: segment[2] + 1, - column: segment[3], - source: sourcemap.sources[segment[1]], - name: sourcemap.names[segment[4]] - }; - locationFound = true; - break; - } - } - } - if (!locationFound) { - throw new Error("Can't resolve original location of error."); - } - } - return location; - } - - // this looks ridiculous, but it prevents sourcemap tooling from mistaking - // this for an actual sourceMappingURL - var SOURCEMAPPING_URL = 'sourceMa'; - SOURCEMAPPING_URL += 'ppingURL'; - var SOURCEMAPPING_URL_RE = new RegExp("^#\\s+" + SOURCEMAPPING_URL + "=.+\\n?"); - - var NOOP = function () { }; - var getStartTime = function () { return 0; }; - var getElapsedTime = function () { return 0; }; - var timers = {}; - var normalizeHrTime = function (time) { return time[0] * 1e3 + time[1] / 1e6; }; - function setTimeHelpers() { - if (typeof process !== 'undefined' && typeof process.hrtime === 'function') { - getStartTime = process.hrtime.bind(process); - getElapsedTime = function (previous) { return normalizeHrTime(process.hrtime(previous)); }; - } - else if (typeof performance !== 'undefined' && typeof performance.now === 'function') { - getStartTime = performance.now.bind(performance); - getElapsedTime = function (previous) { return performance.now() - previous; }; - } - } - function getPersistedLabel(label, level) { - switch (level) { - case 1: - return "# " + label; - case 2: - return "## " + label; - case 3: - return label; - default: - return ' '.repeat(level - 4) + "- " + label; - } - } - function timeStartImpl(label, level) { - if (level === void 0) { level = 3; } - label = getPersistedLabel(label, level); - if (!timers.hasOwnProperty(label)) { - timers[label] = { - start: undefined, - time: 0 - }; - } - timers[label].start = getStartTime(); - } - function timeEndImpl(label, level) { - if (level === void 0) { level = 3; } - label = getPersistedLabel(label, level); - if (timers.hasOwnProperty(label)) { - timers[label].time += getElapsedTime(timers[label].start); - } - } - function getTimings() { - var newTimings = {}; - Object.keys(timers).forEach(function (label) { - newTimings[label] = timers[label].time; - }); - return newTimings; - } - var timeStart = NOOP, timeEnd = NOOP; - var TIMED_PLUGIN_HOOKS = { - transform: true, - transformBundle: true, - load: true, - resolveId: true, - ongenerate: true, - onwrite: true, - resolveDynamicImport: true - }; - function getPluginWithTimers(plugin, index) { - var timedPlugin = {}; - var _loop_1 = function (hook) { - if (TIMED_PLUGIN_HOOKS[hook] === true) { - var timerLabel_1 = "plugin " + index; - if (plugin.name) { - timerLabel_1 += " (" + plugin.name + ")"; - } - timerLabel_1 += " - " + hook; - timedPlugin[hook] = function () { - timeStart(timerLabel_1, 4); - var result = plugin[hook].apply(this === timedPlugin ? plugin : this, arguments); - timeEnd(timerLabel_1, 4); - if (result && typeof result.then === 'function') { - timeStart(timerLabel_1 + " (async)", 4); - result.then(function () { return timeEnd(timerLabel_1 + " (async)", 4); }); - } - return result; - }; - } - else { - timedPlugin[hook] = plugin[hook]; - } - }; - for (var _i = 0, _a = Object.keys(plugin); _i < _a.length; _i++) { - var hook = _a[_i]; - _loop_1(hook); - } - return timedPlugin; - } - function initialiseTimers(inputOptions) { - if (inputOptions.perf) { - timers = {}; - setTimeHelpers(); - timeStart = timeStartImpl; - timeEnd = timeEndImpl; - inputOptions.plugins = inputOptions.plugins.map(getPluginWithTimers); - } - else { - timeStart = NOOP; - timeEnd = NOOP; - } - } - - var defaultAcornOptions = { - // TODO TypeScript waiting for acorn types to be updated - ecmaVersion: 2018, - sourceType: 'module', - preserveParens: false - }; - function tryParse(module, parse, acornOptions) { - try { - return parse(module.code, __assign({}, defaultAcornOptions, acornOptions, { onComment: function (block, text, start, end) { - return module.comments.push({ block: block, text: text, start: start, end: end }); - } })); - } - catch (err) { - module.error({ - code: 'PARSE_ERROR', - message: err.message.replace(/ \(\d+:\d+\)$/, '') - }, err.pos); - } - } - function includeFully(node) { - node.included = true; - if (node.variable && !node.variable.included) { - node.variable.include(); - } - for (var _i = 0, _a = node.keys; _i < _a.length; _i++) { - var key = _a[_i]; - var value = node[key]; - if (value === null) - continue; - if (Array.isArray(value)) { - for (var _b = 0, value_1 = value; _b < value_1.length; _b++) { - var child = value_1[_b]; - if (child !== null) - includeFully(child); - } - } - else { - includeFully(value); - } - } - } - var Module = /** @class */ (function () { - function Module(graph, id) { - this.usesTopLevelAwait = false; - this.namespaceVariable = undefined; - this.needsTreeshakingPass = false; - this.id = id; - this.chunkAlias = undefined; - this.graph = graph; - this.comments = []; - this.dynamicImports = []; - this.importMetas = []; - this.dynamicImportResolutions = []; - this.isEntryPoint = false; - this.execIndex = null; - this.entryPointsHash = new Uint8Array(10); - this.excludeFromSourcemap = /\0/.test(id); - this.context = graph.getModuleContext(id); - // all dependencies - this.sources = []; - this.dependencies = []; - // imports and exports, indexed by local name - this.imports = Object.create(null); - this.exports = Object.create(null); - this.exportsAll = Object.create(null); - this.reexports = Object.create(null); - this.exportAllSources = []; - this.exportAllModules = null; - } - Module.prototype.setSource = function (_a) { - var _this = this; - var code = _a.code, originalCode = _a.originalCode, originalSourcemap = _a.originalSourcemap, ast = _a.ast, sourcemapChain = _a.sourcemapChain, resolvedIds = _a.resolvedIds, transformDependencies = _a.transformDependencies; - this.code = code; - this.originalCode = originalCode; - this.originalSourcemap = originalSourcemap; - this.sourcemapChain = sourcemapChain; - this.transformDependencies = transformDependencies; - timeStart('generate ast', 3); - this.esTreeAst = ast || tryParse(this, this.graph.acornParse, this.graph.acornOptions); - timeEnd('generate ast', 3); - this.resolvedIds = resolvedIds || Object.create(null); - // By default, `id` is the filename. Custom resolvers and loaders - // can change that, but it makes sense to use it for the source filename - var fileName = this.id; - this.magicString = new MagicString(code, { - filename: this.excludeFromSourcemap ? null : fileName, - indentExclusionRanges: [] - }); - this.removeExistingSourceMap(); - timeStart('analyse ast', 3); - this.astContext = { - addDynamicImport: this.addDynamicImport.bind(this), - addExport: this.addExport.bind(this), - addImport: this.addImport.bind(this), - addImportMeta: this.addImportMeta.bind(this), - code: code, - error: this.error.bind(this), - fileName: fileName, - getAssetFileName: this.graph.pluginContext.getAssetFileName, - getExports: this.getExports.bind(this), - getReexports: this.getReexports.bind(this), - getModuleExecIndex: function () { return _this.execIndex; }, - getModuleName: this.basename.bind(this), - imports: this.imports, - includeNamespace: this.includeNamespace.bind(this), - isCrossChunkImport: function (importDescription) { return importDescription.module.chunk !== _this.chunk; }, - magicString: this.magicString, - moduleContext: this.context, - nodeConstructors: nodeConstructors, - propertyReadSideEffects: !this.graph.treeshake || this.graph.treeshakingOptions.propertyReadSideEffects, - deoptimizationTracker: this.graph.deoptimizationTracker, - requestTreeshakingPass: function () { return (_this.needsTreeshakingPass = true); }, - traceExport: this.traceExport.bind(this), - traceVariable: this.traceVariable.bind(this), - treeshake: this.graph.treeshake, - usesTopLevelAwait: false, - varOrConst: this.graph.varOrConst, - warn: this.warn.bind(this) - }; - this.scope = new ModuleScope(this.graph.scope, this.astContext); - this.ast = new Program$1(this.esTreeAst, { type: 'Module', context: this.astContext }, this.scope); - timeEnd('analyse ast', 3); - }; - Module.prototype.removeExistingSourceMap = function () { - for (var _i = 0, _a = this.comments; _i < _a.length; _i++) { - var comment = _a[_i]; - if (!comment.block && SOURCEMAPPING_URL_RE.test(comment.text)) { - this.magicString.remove(comment.start, comment.end); - } - } - }; - Module.prototype.addExport = function (node) { - var source = node.source && node.source.value; - // export { name } from './other' - if (source) { - if (this.sources.indexOf(source) === -1) - this.sources.push(source); - if (node.type === ExportAllDeclaration) { - // Store `export * from '...'` statements in an array of delegates. - // When an unknown import is encountered, we see if one of them can satisfy it. - this.exportAllSources.push(source); - } - else { - for (var _i = 0, _a = node.specifiers; _i < _a.length; _i++) { - var specifier = _a[_i]; - var name = specifier.exported.name; - if (this.exports[name] || this.reexports[name]) { - this.error({ - code: 'DUPLICATE_EXPORT', - message: "A module cannot have multiple exports with the same name ('" + name + "')" - }, specifier.start); - } - this.reexports[name] = { - start: specifier.start, - source: source, - localName: specifier.local.name, - module: null // filled in later - }; - } - } - } - else if (isExportDefaultDeclaration(node)) { - // export default function foo () {} - // export default foo; - // export default 42; - var identifier = (node.declaration.id && - node.declaration.id.name) || - node.declaration.name; - if (this.exports.default) { - this.error({ - code: 'DUPLICATE_EXPORT', - message: "A module can only have one default export" - }, node.start); - } - this.exports.default = { - localName: 'default', - identifier: identifier, - node: node - }; - } - else if (node.declaration) { - // export var { foo, bar } = ... - // export var foo = 42; - // export var a = 1, b = 2, c = 3; - // export function foo () {} - var declaration = node.declaration; - if (declaration.type === VariableDeclaration) { - for (var _b = 0, _c = declaration.declarations; _b < _c.length; _b++) { - var decl = _c[_b]; - for (var _d = 0, _e = extractNames(decl.id); _d < _e.length; _d++) { - var localName = _e[_d]; - this.exports[localName] = { localName: localName, node: node }; - } - } - } - else { - // export function foo () {} - var localName = declaration.id.name; - this.exports[localName] = { localName: localName, node: node }; - } - } - else { - // export { foo, bar, baz } - for (var _f = 0, _g = node.specifiers; _f < _g.length; _f++) { - var specifier = _g[_f]; - var localName = specifier.local.name; - var exportedName = specifier.exported.name; - if (this.exports[exportedName] || this.reexports[exportedName]) { - this.error({ - code: 'DUPLICATE_EXPORT', - message: "A module cannot have multiple exports with the same name ('" + exportedName + "')" - }, specifier.start); - } - this.exports[exportedName] = { localName: localName, node: node }; - } - } - }; - Module.prototype.addImport = function (node) { - var source = node.source.value; - if (this.sources.indexOf(source) === -1) - this.sources.push(source); - for (var _i = 0, _a = node.specifiers; _i < _a.length; _i++) { - var specifier = _a[_i]; - var localName = specifier.local.name; - if (this.imports[localName]) { - this.error({ - code: 'DUPLICATE_IMPORT', - message: "Duplicated import '" + localName + "'" - }, specifier.start); - } - var isDefault = specifier.type === ImportDefaultSpecifier; - var isNamespace = specifier.type === ImportNamespaceSpecifier; - var name = isDefault - ? 'default' - : isNamespace - ? '*' - : specifier.imported.name; - this.imports[localName] = { source: source, start: specifier.start, name: name, module: null }; - } - }; - Module.prototype.addDynamicImport = function (node) { - this.dynamicImports.push(node); - }; - Module.prototype.addImportMeta = function (node) { - this.importMetas.push(node); - }; - Module.prototype.basename = function () { - var base = basename(this.id); - var ext = extname(this.id); - return makeLegal(ext ? base.slice(0, -ext.length) : base); - }; - Module.prototype.markPublicExports = function () { - for (var _i = 0, _a = this.getExports(); _i < _a.length; _i++) { - var exportName = _a[_i]; - var variable = this.traceExport(exportName); - variable.exportName = exportName; - variable.deoptimizePath(UNKNOWN_PATH); - variable.include(); - if (variable.isNamespace) { - variable.needsNamespaceBlock = true; - } - } - for (var _b = 0, _c = this.getReexports(); _b < _c.length; _b++) { - var name = _c[_b]; - var variable = this.traceExport(name); - variable.exportName = name; - if (variable.isExternal) { - variable.reexported = variable.module.reexported = true; - } - else { - variable.include(); - variable.deoptimizePath(UNKNOWN_PATH); - } - } - }; - Module.prototype.linkDependencies = function () { - var _this = this; - for (var _i = 0, _a = this.sources; _i < _a.length; _i++) { - var source = _a[_i]; - var id = this.resolvedIds[source]; - if (id) { - var module = this.graph.moduleById.get(id); - this.dependencies.push(module); - } - } - var resolveSpecifiers = function (specifiers) { - for (var _i = 0, _a = Object.keys(specifiers); _i < _a.length; _i++) { - var name = _a[_i]; - var specifier = specifiers[name]; - var id = _this.resolvedIds[specifier.source]; - specifier.module = _this.graph.moduleById.get(id); - } - }; - resolveSpecifiers(this.imports); - resolveSpecifiers(this.reexports); - this.exportAllModules = this.exportAllSources.map(function (source) { - var id = _this.resolvedIds[source]; - return _this.graph.moduleById.get(id); - }); - }; - Module.prototype.bindReferences = function () { - this.ast.bind(); - }; - Module.prototype.getDynamicImportExpressions = function () { - return this.dynamicImports.map(function (node) { - var importArgument = node.parent.arguments[0]; - if (isTemplateLiteral(importArgument)) { - if (importArgument.expressions.length === 0 && importArgument.quasis.length === 1) { - return importArgument.quasis[0].value.cooked; - } - } - else if (isLiteral(importArgument)) { - if (typeof importArgument.value === 'string') { - return importArgument.value; - } - } - else { - return importArgument; - } - }); - }; - Module.prototype.error = function (props, pos) { - if (pos !== undefined) { - props.pos = pos; - var location = locate(this.code, pos, { offsetLine: 1 }); - try { - location = getOriginalLocation(this.sourcemapChain, location); - } - catch (e) { - this.warn({ - loc: { - file: this.id, - line: location.line, - column: location.column - }, - pos: pos, - message: "Error when using sourcemap for reporting an error: " + e.message, - code: 'SOURCEMAP_ERROR' - }, undefined); - } - props.loc = { - file: this.id, - line: location.line, - column: location.column - }; - props.frame = getCodeFrame(this.originalCode, location.line, location.column); - } - error(props); - }; - Module.prototype.getAllExports = function () { - var allExports = Object.assign(Object.create(null), this.exports, this.reexports); - this.exportAllModules.forEach(function (module) { - if (module.isExternal) { - allExports["*" + module.id] = true; - return; - } - for (var _i = 0, _a = module.getAllExports(); _i < _a.length; _i++) { - var name = _a[_i]; - if (name !== 'default') - allExports[name] = true; - } - }); - return Object.keys(allExports); - }; - Module.prototype.getExports = function () { - return Object.keys(this.exports); - }; - Module.prototype.getReexports = function () { - var reexports = Object.create(null); - for (var name in this.reexports) { - reexports[name] = true; - } - this.exportAllModules.forEach(function (module) { - if (module.isExternal) { - reexports["*" + module.id] = true; - return; - } - for (var _i = 0, _a = module.getExports().concat(module.getReexports()); _i < _a.length; _i++) { - var name = _a[_i]; - if (name !== 'default') - reexports[name] = true; - } - }); - return Object.keys(reexports); - }; - Module.prototype.includeAllInBundle = function () { - includeFully(this.ast); - }; - Module.prototype.isIncluded = function () { - return this.ast.included; - }; - Module.prototype.include = function () { - this.needsTreeshakingPass = false; - if (this.ast.shouldBeIncluded()) - this.ast.include(); - return this.needsTreeshakingPass; - }; - Module.prototype.getOrCreateNamespace = function () { - if (this.namespaceVariable) - return this.namespaceVariable; - return (this.namespaceVariable = new NamespaceVariable(this.astContext)); - }; - Module.prototype.includeNamespace = function () { - var namespace = this.getOrCreateNamespace(); - if (namespace.needsNamespaceBlock) - return; - var hasReexports = false; - for (var importName in this.reexports) { - hasReexports = true; - var reexport = this.reexports[importName]; - this.imports[importName] = { - source: reexport.source, - start: reexport.start, - name: reexport.localName, - module: reexport.module - }; - namespace.originals[importName] = reexport.module.traceExport(reexport.localName); - } - if (this.chunk && this.chunk.linked && hasReexports) - this.chunk.linkModule(this); - }; - Module.prototype.render = function (options) { - var magicString = this.magicString.clone(); - this.ast.render(magicString, options); - this.usesTopLevelAwait = this.astContext.usesTopLevelAwait; - return magicString; - }; - Module.prototype.toJSON = function () { - return { - id: this.id, - dependencies: this.dependencies.map(function (module) { return module.id; }), - transformDependencies: this.transformDependencies, - transformAssets: this.transformAssets, - code: this.code, - originalCode: this.originalCode, - originalSourcemap: this.originalSourcemap, - ast: this.esTreeAst, - sourcemapChain: this.sourcemapChain, - resolvedIds: this.resolvedIds - }; - }; - Module.prototype.traceVariable = function (name) { - // TODO this is slightly circular - if (name in this.scope.variables) { - return this.scope.variables[name]; - } - if (name in this.imports) { - var importDeclaration = this.imports[name]; - var otherModule = importDeclaration.module; - if (!otherModule.isExternal && importDeclaration.name === '*') { - return otherModule.getOrCreateNamespace(); - } - var declaration = otherModule.traceExport(importDeclaration.name); - if (!declaration) { - handleMissingExport(importDeclaration.name, this, otherModule.id, importDeclaration.start); - } - return declaration; - } - return null; - }; - Module.prototype.getRenderedExports = function () { - // only direct exports are counted here, not reexports at all - var renderedExports = []; - var removedExports = []; - for (var exportName in this.exports) { - var expt = this.exports[exportName]; - (expt.node && expt.node.included ? renderedExports : removedExports).push(exportName); - } - return { renderedExports: renderedExports, removedExports: removedExports }; - }; - Module.prototype.traceExport = function (name, isExportAllSearch) { - if (name[0] === '*') { - // namespace - if (name.length === 1) { - return this.getOrCreateNamespace(); - // export * from 'external' - } - else { - var module = this.graph.moduleById.get(name.slice(1)); - return module.traceExport('*'); - } - } - // export { foo } from './other' - var reexportDeclaration = this.reexports[name]; - if (reexportDeclaration) { - var declaration = reexportDeclaration.module.traceExport(reexportDeclaration.localName); - if (!declaration) { - handleMissingExport(reexportDeclaration.localName, this, reexportDeclaration.module.id, reexportDeclaration.start); - } - return declaration; - } - var exportDeclaration = this.exports[name]; - if (exportDeclaration) { - var name_1 = exportDeclaration.localName; - var declaration = this.traceVariable(name_1) || this.graph.scope.findVariable(name_1); - return declaration; - } - if (name !== 'default') { - for (var i = 0; i < this.exportAllModules.length; i += 1) { - var module = this.exportAllModules[i]; - var declaration = module.traceExport(name, true); - if (declaration) - return declaration; - } - } - // we don't want to create shims when we are just - // probing export * modules for exports - if (this.graph.shimMissingExports && !isExportAllSearch) { - return this.shimMissingExport(name); - } - }; - Module.prototype.warn = function (warning, pos) { - if (pos !== undefined) { - warning.pos = pos; - var _a = locate(this.code, pos, { offsetLine: 1 }), line = _a.line, column = _a.column; // TODO trace sourcemaps, cf. error() - warning.loc = { file: this.id, line: line, column: column }; - warning.frame = getCodeFrame(this.code, line, column); - } - warning.id = this.id; - this.graph.warn(warning); - }; - Module.prototype.shimMissingExport = function (name) { - // could have already been generated - if (!this.exports[name]) - this.graph.warn({ - message: "Missing export \"" + name + "\" has been shimmed in module " + relativeId(this.id) + ".", - code: 'SHIMMED_EXPORT', - exportName: name, - exporter: relativeId(this.id) - }); - this.exports[name] = { - localName: '_missingExportShim' - }; - return this.graph.exportShimVariable; - }; - return Module; - }()); - - var Source = /** @class */ (function () { - function Source(filename, content) { - this.isOriginal = true; - this.filename = filename; - this.content = content; - } - Source.prototype.traceSegment = function (line, column, name) { - return { line: line, column: column, name: name, source: this }; - }; - return Source; - }()); - var Link = /** @class */ (function () { - function Link(map, sources) { - this.sources = sources; - this.names = map.names; - this.mappings = map.mappings; - } - Link.prototype.traceMappings = function () { - var sources = []; - var sourcesContent = []; - var names = []; - var mappings = []; - for (var _i = 0, _a = this.mappings; _i < _a.length; _i++) { - var line = _a[_i]; - var tracedLine = []; - for (var _b = 0, line_1 = line; _b < line_1.length; _b++) { - var segment = line_1[_b]; - var source = this.sources[segment[1]]; - if (!source) - continue; - var traced = source.traceSegment(segment[2], segment[3], this.names[segment[4]]); - if (traced) { - // newer sources are more likely to be used, so search backwards. - var sourceIndex = sources.lastIndexOf(traced.source.filename); - if (sourceIndex === -1) { - sourceIndex = sources.length; - sources.push(traced.source.filename); - sourcesContent[sourceIndex] = traced.source.content; - } - else if (sourcesContent[sourceIndex] == null) { - sourcesContent[sourceIndex] = traced.source.content; - } - else if (traced.source.content != null && - sourcesContent[sourceIndex] !== traced.source.content) { - error({ - message: "Multiple conflicting contents for sourcemap source " + traced.source.filename - }); - } - var tracedSegment = [ - segment[0], - sourceIndex, - traced.line, - traced.column - ]; - if (traced.name) { - var nameIndex = names.indexOf(traced.name); - if (nameIndex === -1) { - nameIndex = names.length; - names.push(traced.name); - } - tracedSegment[4] = nameIndex; - } - tracedLine.push(tracedSegment); - } - } - mappings.push(tracedLine); - } - return { sources: sources, sourcesContent: sourcesContent, names: names, mappings: mappings }; - }; - Link.prototype.traceSegment = function (line, column, name) { - var segments = this.mappings[line]; - if (!segments) - return null; - // binary search through segments for the given column - var i = 0; - var j = segments.length - 1; - while (i <= j) { - var m = (i + j) >> 1; - var segment = segments[m]; - if (segment[0] === column) { - var source = this.sources[segment[1]]; - if (!source) - return null; - return source.traceSegment(segment[2], segment[3], this.names[segment[4]] || name); - } - if (segment[0] > column) { - j = m - 1; - } - else { - i = m + 1; - } - } - return null; - }; - return Link; - }()); - // TODO TypeScript: Fix typecasts - function collapseSourcemaps(bundle, file, map, modules, bundleSourcemapChain) { - var moduleSources = modules.filter(function (module) { return !module.excludeFromSourcemap; }).map(function (module) { - var sourcemapChain = module.sourcemapChain; - var source; - var originalSourcemap = module.originalSourcemap; - if (!originalSourcemap) { - source = new Source(module.id, module.originalCode); - } - else { - var sources_1 = originalSourcemap.sources; - var sourcesContent_1 = originalSourcemap.sourcesContent || []; - if (sources_1 == null || (sources_1.length <= 1 && sources_1[0] == null)) { - source = new Source(module.id, sourcesContent_1[0]); - sourcemapChain = [originalSourcemap].concat(sourcemapChain); - } - else { - // TODO indiscriminately treating IDs and sources as normal paths is probably bad. - var directory_1 = dirname(module.id) || '.'; - var sourceRoot_1 = originalSourcemap.sourceRoot || '.'; - var baseSources = sources_1.map(function (source, i) { - return new Source(resolve(directory_1, sourceRoot_1, source), sourcesContent_1[i]); - }); - source = new Link(originalSourcemap, baseSources); - } - } - sourcemapChain.forEach(function (map) { - if (map.missing) { - bundle.graph.warn({ - code: 'SOURCEMAP_BROKEN', - plugin: map.plugin, - message: "Sourcemap is likely to be incorrect: a plugin" + (map.plugin ? " ('" + map.plugin + "')" : "") + " was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help", - url: "https://github.com/rollup/rollup/wiki/Troubleshooting#sourcemap-is-likely-to-be-incorrect" - }); - map = { - names: [], - mappings: '' - }; - } - source = new Link(map, [source]); - }); - return source; - }); - var source = new Link(map, moduleSources); - bundleSourcemapChain.forEach(function (map) { - source = new Link(map, [source]); - }); - var _a = source.traceMappings(), sources = _a.sources, sourcesContent = _a.sourcesContent, names = _a.names, mappings = _a.mappings; - if (file) { - var directory_2 = dirname(file); - sources = sources.map(function (source) { return relative(directory_2, source); }); - file = basename(file); - } - return new SourceMap({ file: file, sources: sources, sourcesContent: sourcesContent, names: names, mappings: mappings }); - } - - function guessIndentString(code) { - var lines = code.split('\n'); - var tabbed = lines.filter(function (line) { return /^\t+/.test(line); }); - var spaced = lines.filter(function (line) { return /^ {2,}/.test(line); }); - if (tabbed.length === 0 && spaced.length === 0) { - return null; - } - // More lines tabbed than spaced? Assume tabs, and - // default to tabs in the case of a tie (or nothing - // to go on) - if (tabbed.length >= spaced.length) { - return '\t'; - } - // Otherwise, we need to guess the multiple - var min = spaced.reduce(function (previous, current) { - var numSpaces = /^ +/.exec(current)[0].length; - return Math.min(numSpaces, previous); - }, Infinity); - return new Array(min + 1).join(' '); - } - function getIndentString(modules, options) { - if (options.indent !== true) - return options.indent || ''; - for (var i = 0; i < modules.length; i++) { - var indent = guessIndentString(modules[i].originalCode); - if (indent !== null) - return indent; - } - return '\t'; - } - - function renderNamePattern(pattern, patternName, getReplacement) { - if (!isPlainName(pattern)) - error({ - code: 'INVALID_PATTERN', - message: "Invalid output pattern \"" + pattern + "\" for " + patternName + ", cannot be an absolute or relative URL or path." - }); - return pattern.replace(/\[(\w+)\]/g, function (_match, type) { - var replacement = getReplacement(type); - if (replacement === undefined) - error({ - code: 'INVALID_PATTERN_REPLACEMENT', - message: "\"" + type + "\" is not a valid substitution name in output option " + patternName + " pattern." - }); - if (!isPlainName(replacement)) - error({ - code: 'INVALID_PATTERN_REPLACEMENT', - message: "Invalid replacement \"" + replacement + "\" for \"" + type + "\" in " + patternName + " pattern, must be a plain path name." - }); - return replacement; - }); - } - function makeUnique(name, existingNames) { - if (name in existingNames === false) - return name; - var ext = extname(name); - name = name.substr(0, name.length - ext.length); - var uniqueName, uniqueIndex = 1; - while (existingNames[(uniqueName = name + ++uniqueIndex + ext)]) - ; - return uniqueName; - } - - function transformChunk(graph, chunk, code, sourcemapChain, options) { - return graph.plugins.reduce(function (promise, plugin) { - if (!plugin.transformBundle && !plugin.transformChunk) - return promise; - return promise.then(function (code) { - return Promise.resolve() - .then(function () { - return (plugin.transformChunk || plugin.transformBundle).call(graph.pluginContext, code, options, chunk); - }) - .then(function (result) { - if (result == null) - return code; - if (plugin.transformBundle) { - if (typeof result === 'string') { - result = { - code: result, - map: undefined - }; - } - } - else if (typeof result === 'string') { - throw new Error('transformChunk must return a { code, map } object, not a string.'); - } - else if (!result.map && options.sourcemap) { - throw new Error('transformChunk must return a "map" sourcemap property when sourcemaps are enabled.'); - } - var map = typeof result.map === 'string' ? JSON.parse(result.map) : result.map; - if (map && typeof map.mappings === 'string') { - map.mappings = decode(map.mappings); - } - // strict null check allows 'null' maps to not be pushed to the chain, while 'undefined' gets the missing map warning - if (map !== null) { - sourcemapChain.push(map || { missing: true, plugin: plugin.name }); - } - return result.code; - }) - .catch(function (err) { - error({ - code: plugin.transformChunk ? 'BAD_CHUNK_TRANSFORMER' : 'BAD_BUNDLE_TRANSFORMER', - message: "Error transforming " + ((plugin.transformChunk ? 'chunk' : 'bundle') + - (plugin.name ? " with '" + plugin.name + "' plugin" : '')) + ": " + err.message, - plugin: plugin.name - }); - }); - }); - }, Promise.resolve(code)); - } - - function getGlobalName(module, globals, graph, hasExports) { - if (typeof globals === 'function') - return globals(module.id); - if (globals) - return globals[module.id]; - if (hasExports) { - graph.warn({ - code: 'MISSING_GLOBAL_NAME', - source: module.id, - guess: module.name, - message: "No name was provided for external module '" + module.id + "' in output.globals \u2013 guessing '" + module.name + "'" - }); - return module.name; - } - } - var Chunk$1 = /** @class */ (function () { - function Chunk(graph, orderedModules) { - this.hasDynamicImport = false; - this.indentString = undefined; - this.exportMode = 'named'; - this.usedModules = undefined; - this.id = undefined; - this.linked = false; - // this represents the chunk module wrappings - // which form the output dependency graph - this.imports = new Map(); - // module can be in or out of chunk - // if module is out of the chunk then it is a reexport - this.exports = new Map(); - this.exportNames = Object.create(null); - this.dependencies = undefined; - // an entry module chunk is a chunk that exactly exports the exports of - // an input entry point module - this.entryModule = undefined; - this.isEntryModuleFacade = false; - this.isManualChunk = false; - this.renderedHash = undefined; - this.renderedModuleSources = undefined; - this.renderedSource = undefined; - this.renderedSourceLength = undefined; - this.needsExportsShim = false; - this.renderedDeclarations = undefined; - this.graph = graph; - this.orderedModules = orderedModules; - this.isEmpty = true; - for (var _i = 0, orderedModules_1 = orderedModules; _i < orderedModules_1.length; _i++) { - var module = orderedModules_1[_i]; - if (this.isEmpty && module.isIncluded()) { - this.isEmpty = false; - } - if (module.chunkAlias) { - this.isManualChunk = true; - } - module.chunk = this; - if (module.isEntryPoint && !this.entryModule) { - this.entryModule = module; - this.isEntryModuleFacade = true; - } - } - if (this.entryModule) - this.name = makeLegal(basename(this.entryModule.chunkAlias || this.orderedModules[0].chunkAlias || this.entryModule.id)); - else - this.name = '__chunk_' + ++graph.curChunkIndex; - } - Chunk.prototype.getImportIds = function () { - return this.dependencies.map(function (module) { return module.id; }); - }; - Chunk.prototype.getExportNames = function () { - return Object.keys(this.exportNames); - }; - Chunk.prototype.inlineChunkDependencies = function (chunk, deep) { - for (var _i = 0, _a = chunk.dependencies; _i < _a.length; _i++) { - var dep = _a[_i]; - if (dep instanceof ExternalModule) { - if (this.dependencies.indexOf(dep) === -1) - this.dependencies.push(dep); - } - else { - if (dep === this || this.dependencies.indexOf(dep) !== -1) - continue; - if (!dep.isEmpty) - this.dependencies.push(dep); - if (deep) - this.inlineChunkDependencies(dep, true); - } - } - }; - // note we assume the facade module chunk is itself linked - // with generateEntryExports called - Chunk.prototype.linkFacade = function (entryFacade) { - this.dependencies = [entryFacade.chunk]; - this.entryModule = entryFacade; - this.isEntryModuleFacade = true; - for (var _i = 0, _a = entryFacade.getAllExports(); _i < _a.length; _i++) { - var exportName = _a[_i]; - var tracedVariable = entryFacade.traceExport(exportName); - this.exports.set(tracedVariable, entryFacade); - this.exportNames[exportName] = tracedVariable; - } - }; - Chunk.prototype.link = function () { - this.dependencies = []; - for (var _i = 0, _a = this.orderedModules; _i < _a.length; _i++) { - var module = _a[_i]; - this.linkModule(module); - } - this.linked = true; - }; - Chunk.prototype.linkModule = function (module) { - for (var _i = 0, _a = module.dependencies; _i < _a.length; _i++) { - var dep = _a[_i]; - if (dep.chunk === this) { - continue; - } - var depModule = void 0; - if (dep instanceof Module) { - depModule = dep.chunk; - } - else { - // unused pure external modules can be skipped - if (!dep.used && this.graph.isPureExternalModule(dep.id)) { - continue; - } - depModule = dep; - } - if (this.dependencies.indexOf(depModule) === -1) { - this.dependencies.push(depModule); - } - } - for (var _b = 0, _c = Object.keys(module.imports); _b < _c.length; _b++) { - var importName = _c[_b]; - var declaration = module.imports[importName]; - this.traceImport(declaration.name, declaration.module); - } - for (var _d = 0, _e = module.dynamicImportResolutions; _d < _e.length; _d++) { - var resolution = _e[_d].resolution; - this.hasDynamicImport = true; - if (resolution instanceof Module && resolution.chunk === this) - resolution.getOrCreateNamespace().include(); - } - }; - // Note preserveModules implementation is not a comprehensive technique - // this will likely need to be reworked at some stage for edge cases - Chunk.prototype.populateEntryExports = function (preserveModules) { - var entryExportEntries = Array.from(this.entryModule.getAllExports().entries()); - var tracedExports = []; - for (var _i = 0, entryExportEntries_1 = entryExportEntries; _i < entryExportEntries_1.length; _i++) { - var _a = entryExportEntries_1[_i], index = _a[0], exportName = _a[1]; - var traced = this.traceExport(exportName, this.entryModule); - if (traced.variable && !traced.variable.included && !traced.variable.isExternal) { - continue; - } - tracedExports[index] = traced; - if (!traced.variable) { - continue; - } - if (traced.module.chunk) { - traced.module.chunk.exports.set(traced.variable, traced.module); - } - var existingExport = this.exportNames[exportName]; - // tainted entryModule boundary - if (existingExport && existingExport !== traced.variable) { - this.isEntryModuleFacade = false; - } - } - var _loop_1 = function (exposedVariable) { - if (tracedExports.every(function (_a) { - var variable = _a.variable; - return variable !== exposedVariable; - })) { - this_1.isEntryModuleFacade = false; - return { value: void 0 }; - } - }; - var this_1 = this; - // tainted if we've already exposed something not corresponding to entry exports - for (var _b = 0, _c = Array.from(this.exports.keys()); _b < _c.length; _b++) { - var exposedVariable = _c[_b]; - var state_1 = _loop_1(exposedVariable); - if (typeof state_1 === "object") - return state_1.value; - } - if (preserveModules || this.isEntryModuleFacade) { - for (var _d = 0, entryExportEntries_2 = entryExportEntries; _d < entryExportEntries_2.length; _d++) { - var _e = entryExportEntries_2[_d], index = _e[0], exportName = _e[1]; - var traced = tracedExports[index]; - if (!traced) { - continue; - } - if (traced.variable) { - if (!traced.variable.included && !traced.variable.isExternal) { - continue; - } - this.exports.set(traced.variable, traced.module); - } - // can be undefined for star external exports (exportName[0] === '*') - this.exportNames[exportName] = traced.variable; - } - } - }; - Chunk.prototype.traceImport = function (exportName, module) { - var traced = this.traceExport(exportName, module); - // ignore imports to modules already in this chunk - if (!traced || traced.module.chunk === this) { - return traced; - } - // namespace variable can indicate multiple imports - if (traced.variable.isNamespace) { - var namespaceVariables = traced.variable.originals || - traced.variable.module.declarations; - for (var _i = 0, _a = Object.keys(namespaceVariables); _i < _a.length; _i++) { - var importName = _a[_i]; - var original = namespaceVariables[importName]; - if (original.included) { - if (traced.module.chunk) { - traced.module.chunk.exports.set(original, traced.module); - } - this.imports.set(original, traced.module); - } - } - } - if (!traced.variable.included) { - return traced; - } - this.imports.set(traced.variable, traced.module); - if (traced.module instanceof Module) { - traced.module.chunk.exports.set(traced.variable, traced.module); - } - return traced; - }; - // trace a module export to its exposed chunk module export - // either in this chunk or in another - Chunk.prototype.traceExport = function (name, module) { - if (name === '*' || module instanceof ExternalModule) { - return { variable: module.traceExport(name), module: module }; - } - if (module.chunk !== this) { - // we follow reexports if they are not entry points in the hope - // that we can get an entry point reexport to reduce the chance of - // tainting an entryModule chunk by exposing other unnecessary exports - if (module.isEntryPoint && !module.chunk.isEmpty) - return { variable: module.traceExport(name), module: module }; - return module.chunk.traceExport(name, module); - } - var exportDeclaration = module.exports[name]; - if (exportDeclaration) { - // if export binding is itself an import binding then continue tracing - var importDeclaration = module.imports[exportDeclaration.localName]; - if (importDeclaration) { - return this.traceImport(importDeclaration.name, importDeclaration.module); - } - return { variable: module.traceExport(name), module: module }; - } - var reexportDeclaration = module.reexports[name]; - if (reexportDeclaration) { - return this.traceExport(reexportDeclaration.localName, reexportDeclaration.module); - } - if (name === 'default') { - return; - } - // external star exports - if (name[0] === '*') { - return { variable: undefined, module: this.graph.moduleById.get(name.substr(1)) }; - } - // resolve known star exports - for (var i = 0; i < module.exportAllModules.length; i++) { - var exportAllModule = module.exportAllModules[i]; - // we have to ensure the right export all module - if (exportAllModule.traceExport(name, true)) { - return this.traceExport(name, exportAllModule); - } - } - }; - Chunk.prototype.getVariableExportName = function (variable) { - for (var _i = 0, _a = Object.keys(this.exportNames); _i < _a.length; _i++) { - var exportName = _a[_i]; - if (this.exportNames[exportName] === variable) - return exportName; - } - }; - Chunk.prototype.generateInternalExports = function (options) { - if (this.isEntryModuleFacade) - return; - var mangle = options.format === 'system' || options.format === 'es' || options.compact; - var i = 0, safeExportName; - this.exportNames = Object.create(null); - var exportedVariables = Array.from(this.exports.keys()); - if (mangle) { - for (var _i = 0, exportedVariables_1 = exportedVariables; _i < exportedVariables_1.length; _i++) { - var variable = exportedVariables_1[_i]; - safeExportName = toBase64(++i); - // skip past leading number identifiers - if (safeExportName.charCodeAt(0) === 49 /* '1' */) { - i += 9 * Math.pow(64, (safeExportName.length - 1)); - safeExportName = toBase64(i); - } - this.exportNames[safeExportName] = variable; - } - } - else { - for (var _a = 0, exportedVariables_2 = exportedVariables; _a < exportedVariables_2.length; _a++) { - var variable = exportedVariables_2[_a]; - i = 0; - safeExportName = variable.name; - while (this.exportNames[safeExportName]) { - safeExportName = variable.name + '$' + ++i; - } - this.exportNames[safeExportName] = variable; - } - } - }; - Chunk.prototype.prepareDynamicImports = function () { - for (var _i = 0, _a = this.orderedModules; _i < _a.length; _i++) { - var module = _a[_i]; - for (var i = 0; i < module.dynamicImportResolutions.length; i++) { - var node = module.dynamicImports[i]; - var resolution = module.dynamicImportResolutions[i].resolution; - if (!resolution) - continue; - if (resolution instanceof Module) { - // if we have the module in the chunk, inline as Promise.resolve(namespace) - // ensuring that we create a namespace import of it as well - if (resolution.chunk === this) { - var namespace = resolution.getOrCreateNamespace(); - node.setResolution(false, namespace.getName()); - // for the module in another chunk, import that other chunk directly - } - else { - node.setResolution(false); - } - // external dynamic import resolution - } - else if (resolution instanceof ExternalModule) { - node.setResolution(true); - // AST Node -> source replacement - } - else { - node.setResolution(false); - } - } - } - }; - Chunk.prototype.finaliseDynamicImports = function () { - for (var i = 0; i < this.orderedModules.length; i++) { - var module = this.orderedModules[i]; - var code = this.renderedModuleSources[i]; - for (var j = 0; j < module.dynamicImportResolutions.length; j++) { - var node = module.dynamicImports[j]; - var resolution = module.dynamicImportResolutions[j].resolution; - if (!resolution) - continue; - if (resolution instanceof Module) { - if (resolution.chunk !== this) { - var relPath = normalize(relative(dirname(this.id), resolution.chunk.id)); - if (!relPath.startsWith('../')) - relPath = './' + relPath; - node.renderFinalResolution(code, "\"" + relPath + "\""); - } - } - else if (resolution instanceof ExternalModule) { - node.renderFinalResolution(code, "\"" + resolution.id + "\""); - // AST Node -> source replacement - } - else { - node.renderFinalResolution(code, resolution); - } - } - } - }; - Chunk.prototype.finaliseImportMetas = function (options) { - var usesMechanism = false; - for (var i = 0; i < this.orderedModules.length; i++) { - var module = this.orderedModules[i]; - var code = this.renderedModuleSources[i]; - for (var _i = 0, _a = module.importMetas; _i < _a.length; _i++) { - var importMeta = _a[_i]; - if (importMeta.renderFinalMechanism(code, this.id, options.format, options.compact)) - usesMechanism = true; - } - } - return usesMechanism; - }; - Chunk.prototype.setIdentifierRenderResolutions = function (options) { - var _this = this; - this.needsExportsShim = false; - var used = Object.create(null); - var esm = options.format === 'es' || options.format === 'system'; - // ensure no conflicts with globals - Object.keys(this.graph.scope.variables).forEach(function (name) { return (used[name] = 1); }); - function getSafeName(name) { - var safeName = name; - while (used[safeName]) { - safeName = name + "$" + toBase64(used[name]++, true); - } - used[safeName] = 1; - return safeName; - } - // reserved internal binding names for system format wiring - if (options.format === 'system') { - used._setter = used._starExcludes = used._$p = 1; - } - var toDeshadow = new Set(); - if (!esm) { - this.dependencies.forEach(function (module) { - var safeName = getSafeName(module.name); - toDeshadow.add(safeName); - module.name = safeName; - }); - } - for (var _i = 0, _a = Object.keys(this.exportNames); _i < _a.length; _i++) { - var exportName = _a[_i]; - var exportVariable = this.exportNames[exportName]; - if (exportVariable === this.graph.exportShimVariable) - this.needsExportsShim = true; - if (exportVariable && exportVariable.exportName !== exportName) - exportVariable.exportName = exportName; - } - Array.from(this.imports.entries()).forEach(function (_a) { - var variable = _a[0], module = _a[1]; - var safeName; - if (module instanceof ExternalModule) { - if (variable.name === '*') { - safeName = module.name; - } - else if (variable.name === 'default') { - if (options.interop !== false && - (module.exportsNamespace || (!esm && module.exportsNames))) { - safeName = module.name + "__default"; - } - else { - safeName = module.name; - } - } - else { - safeName = esm ? variable.name : module.name + "." + variable.name; - } - if (esm) { - safeName = getSafeName(safeName); - toDeshadow.add(safeName); - } - } - else if (esm) { - safeName = getSafeName(variable.name); - toDeshadow.add(safeName); - } - else { - var chunk = module.chunk; - if (chunk.exportMode === 'default') - safeName = chunk.name; - else - safeName = chunk.name + "." + module.chunk.getVariableExportName(variable); - } - if (safeName) - variable.setSafeName(safeName); - }); - this.orderedModules.forEach(function (module) { - _this.deconflictExportsOfModule(module, getSafeName, esm); - }); - this.graph.scope.deshadow(toDeshadow, this.orderedModules.map(function (module) { return module.scope; })); - }; - Chunk.prototype.deconflictExportsOfModule = function (module, getSafeName, esm) { - Object.keys(module.scope.variables).forEach(function (variableName) { - var variable = module.scope.variables[variableName]; - if (isExportDefaultVariable(variable) && variable.referencesOriginal()) { - variable.setSafeName(null); - return; - } - if (!(isExportDefaultVariable(variable) && variable.hasId)) { - var safeName = void 0; - if (esm || !variable.isReassigned || variable.isId) { - safeName = getSafeName(variable.name); - } - else { - var safeExportName = variable.exportName; - if (safeExportName) { - safeName = "exports." + safeExportName; - } - else { - safeName = getSafeName(variable.name); - } - } - variable.setSafeName(safeName); - } - }); - // deconflict reified namespaces - var namespace = module.getOrCreateNamespace(); - if (namespace.needsNamespaceBlock) { - namespace.setSafeName(getSafeName(namespace.name)); - } - }; - Chunk.prototype.getChunkDependencyDeclarations = function (options, inputBase) { - var _this = this; - var reexportDeclarations = new Map(); - for (var _i = 0, _a = Object.keys(this.exportNames); _i < _a.length; _i++) { - var exportName = _a[_i]; - var exportModule = void 0; - var importName = void 0; - if (exportName[0] === '*') { - exportModule = this.graph.moduleById.get(exportName.substr(1)); - importName = exportName = '*'; - } - else { - var variable = this.exportNames[exportName]; - var module = this.exports.get(variable); - // skip local exports - if (module.chunk === this) - continue; - if (module instanceof Module) { - exportModule = module.chunk; - importName = module.chunk.getVariableExportName(variable); - } - else { - exportModule = module; - importName = variable.name; - } - } - var exportDeclaration = reexportDeclarations.get(exportModule); - if (!exportDeclaration) - reexportDeclarations.set(exportModule, (exportDeclaration = [])); - exportDeclaration.push({ imported: importName, reexported: exportName }); - } - var dependencies = []; - this.dependencies.forEach(function (dep) { - var importSpecifiers = Array.from(_this.imports.entries()).filter(function (_a) { - var module = _a[1]; - return (module instanceof Module ? module.chunk === dep : module === dep); - }); - var imports; - if (importSpecifiers.length) { - imports = []; - for (var _i = 0, importSpecifiers_1 = importSpecifiers; _i < importSpecifiers_1.length; _i++) { - var _a = importSpecifiers_1[_i], variable = _a[0], module = _a[1]; - var local = variable.safeName || variable.name; - var imported = void 0; - if (module instanceof ExternalModule) { - imported = variable.name; - } - else { - imported = module.chunk.getVariableExportName(variable); - } - imports.push({ local: local, imported: imported }); - } - } - var reexports = reexportDeclarations.get(dep); - var exportsNames, exportsDefault; - var namedExportsMode = true; - if (dep instanceof ExternalModule) { - exportsNames = dep.exportsNames || dep.exportsNamespace; - exportsDefault = 'default' in dep.declarations; - } - else { - exportsNames = true; - // we don't want any interop patterns to trigger - exportsDefault = false; - namedExportsMode = dep.exportMode !== 'default'; - } - var id; - var globalName; - if (dep instanceof ExternalModule) { - id = dep.renderPath || dep.setRenderPath(options, inputBase); - if (options.format === 'umd' || options.format === 'iife') { - globalName = getGlobalName(dep, options.globals, _this.graph, exportsNames || exportsDefault); - } - } - dependencies.push({ - id: id, - namedExportsMode: namedExportsMode, - globalName: globalName, - name: dep.name, - isChunk: !dep.isExternal, - exportsNames: exportsNames, - exportsDefault: exportsDefault, - reexports: reexports, - imports: imports - }); - }); - return dependencies; - }; - Chunk.prototype.getChunkExportDeclarations = function () { - var exports = []; - var _loop_2 = function (exportName) { - if (exportName[0] === '*') - return "continue"; - var variable = this_2.exportNames[exportName]; - var module = this_2.exports.get(variable); - // skip external exports - if (module.chunk !== this_2) - return "continue"; - // determine if a hoisted export (function) - var hoisted = false; - var uninitialized = false; - if (variable instanceof LocalVariable) { - if (variable.init === UNDEFINED_EXPRESSION) { - uninitialized = true; - } - variable.declarations.forEach(function (decl) { - if (decl.type === ExportDefaultDeclaration) { - if (decl.declaration.type === FunctionDeclaration) - hoisted = true; - } - else if (decl.parent.type === FunctionDeclaration) { - hoisted = true; - } - }); - } - else if (variable instanceof GlobalVariable) { - hoisted = true; - } - var localName = variable.getName(); - exports.push({ - local: localName, - exported: exportName === '*' ? localName : exportName, - hoisted: hoisted, - uninitialized: uninitialized - }); - }; - var this_2 = this; - for (var _i = 0, _a = Object.keys(this.exportNames); _i < _a.length; _i++) { - var exportName = _a[_i]; - _loop_2(exportName); - } - return exports; - }; - Chunk.prototype.getRenderedHash = function () { - if (this.renderedHash) - return this.renderedHash; - var hash = _256(); - hash.update(this.renderedSource.toString()); - return (this.renderedHash = hash.digest('hex')); - }; - /* - * Chunk dependency output graph post-visitor - * Visitor can return "true" to indicate a propogated stop condition - */ - Chunk.prototype.postVisitChunkDependencies = function (visitor) { - var seen = new Set(); - // add in hashes of all dependent chunks and resolved external ids - function visitDep(dep) { - if (seen.has(dep)) - return; - seen.add(dep); - if (dep instanceof Chunk) { - for (var _i = 0, _a = dep.dependencies; _i < _a.length; _i++) { - var subDep = _a[_i]; - if (visitDep(subDep)) - return true; - } - } - return visitor(dep) === true; - } - return visitDep(this); - }; - Chunk.prototype.computeFullHash = function (addons, options) { - var hash = _256(); - // own rendered source, except for finalizer wrapping - hash.update(this.getRenderedHash()); - // hash of addons - hash.update(addons.hash); - // output options - hash.update(options.format); - // import names of dependency sources - hash.update(this.dependencies.length); - // add in hashes of all dependent chunks and resolved external ids - this.postVisitChunkDependencies(function (dep) { - if (dep instanceof ExternalModule) - hash.update(':' + dep.renderPath); - else - hash.update(dep.getRenderedHash()); - }); - return hash.digest('hex').substr(0, 8); - }; - // prerender allows chunk hashes and names to be generated before finalizing - Chunk.prototype.preRender = function (options, inputBase) { - timeStart('render modules', 3); - var magicString = new Bundle({ separator: options.compact ? '' : '\n\n' }); - this.usedModules = []; - this.indentString = options.compact ? '' : getIndentString(this.orderedModules, options); - var n = options.compact ? '' : '\n'; - var _ = options.compact ? '' : ' '; - var renderOptions = { - compact: options.compact, - freeze: options.freeze !== false, - esModule: options.esModule !== false, - namespaceToStringTag: options.namespaceToStringTag === true, - indent: this.indentString, - format: options.format - }; - // if an entry point facade, inline the execution list to avoid loading latency - if (this.isEntryModuleFacade) { - for (var _i = 0, _a = this.dependencies; _i < _a.length; _i++) { - var dep = _a[_i]; - if (dep instanceof Chunk) - this.inlineChunkDependencies(dep, true); - } - } - else { - // shortcut cross-chunk relations can be added by traceExport - for (var _b = 0, _c = Array.from(this.imports.values()); _b < _c.length; _b++) { - var module = _c[_b]; - var chunkOrExternal = module instanceof Module ? module.chunk : module; - if (this.dependencies.indexOf(chunkOrExternal) === -1) { - this.dependencies.push(chunkOrExternal); - } - } - } - // prune empty dependency chunks, inlining their side-effect dependencies - for (var i = 0; i < this.dependencies.length; i++) { - var dep = this.dependencies[i]; - if (dep instanceof Chunk && dep.isEmpty) { - this.dependencies.splice(i--, 1); - this.inlineChunkDependencies(dep, false); - } - } - this.setIdentifierRenderResolutions(options); - this.prepareDynamicImports(); - var hoistedSource = ''; - this.renderedModules = Object.create(null); - this.renderedModuleSources = []; - for (var i = 0; i < this.orderedModules.length; i++) { - var module = this.orderedModules[i]; - var source = module.render(renderOptions); - source.trim(); - if (options.compact && source.lastLine().indexOf('//') !== -1) - source.append('\n'); - this.renderedModuleSources.push(source); - var _d = module.getRenderedExports(), renderedExports = _d.renderedExports, removedExports = _d.removedExports; - this.renderedModules[module.id] = { - renderedExports: renderedExports, - removedExports: removedExports, - renderedLength: source.length(), - originalLength: module.originalCode.length - }; - var namespace = module.getOrCreateNamespace(); - if (namespace.needsNamespaceBlock || !source.isEmpty()) { - magicString.addSource(source); - this.usedModules.push(module); - if (namespace.needsNamespaceBlock) { - var rendered = namespace.renderBlock(renderOptions); - if (namespace.renderFirst()) - hoistedSource += n + rendered; - else - magicString.addSource(new MagicString(rendered)); - } - } - } - if (hoistedSource) - magicString.prepend(hoistedSource + n + n); - if (this.needsExportsShim) { - magicString.prepend("" + n + this.graph.varOrConst + " _missingExportShim" + _ + "=" + _ + "void 0;" + n + n); - } - if (options.compact) { - this.renderedSource = magicString; - } - else { - this.renderedSource = magicString.trim(); - } - this.renderedSourceLength = undefined; - this.renderedHash = undefined; - if (this.getExportNames().length === 0 && this.getImportIds().length === 0 && this.isEmpty) { - this.graph.warn({ - code: 'EMPTY_BUNDLE', - message: 'Generated an empty bundle' - }); - } - this.renderedDeclarations = { - dependencies: this.getChunkDependencyDeclarations(options, inputBase), - exports: this.exportMode === 'none' ? [] : this.getChunkExportDeclarations() - }; - timeEnd('render modules', 3); - }; - Chunk.prototype.getRenderedSourceLength = function () { - if (this.renderedSourceLength !== undefined) - return this.renderedSourceLength; - return (this.renderedSourceLength = this.renderedSource.length()); - }; - /* - * Performs a full merge of another chunk into this chunk - * chunkList allows updating references in other chunks for the merged chunk to this chunk - * A new facade will be added to chunkList if tainting exports of either as an entry point - */ - Chunk.prototype.merge = function (chunk, chunkList, options, inputBase) { - var _this = this; - if (this.isEntryModuleFacade || chunk.isEntryModuleFacade) - throw new Error('Internal error: Code splitting chunk merges not supported for facades'); - for (var _i = 0, _a = chunk.orderedModules; _i < _a.length; _i++) { - var module = _a[_i]; - module.chunk = this; - this.orderedModules.push(module); - } - for (var _b = 0, _c = Array.from(chunk.imports.entries()); _b < _c.length; _b++) { - var _d = _c[_b], variable = _d[0], module = _d[1]; - if (!this.imports.has(variable) && module.chunk !== this) { - this.imports.set(variable, module); - } - } - // NB detect when exported variables are orphaned by the merge itself - // (involves reverse tracing dependents) - for (var _e = 0, _f = Array.from(chunk.exports.entries()); _e < _f.length; _e++) { - var _g = _f[_e], variable = _g[0], module = _g[1]; - if (!this.exports.has(variable)) { - this.exports.set(variable, module); - } - } - var thisOldExportNames = this.exportNames; - // regenerate internal names - this.generateInternalExports(options); - var updateRenderedDeclaration = function (dep, oldExportNames) { - if (dep.imports) { - for (var _i = 0, _a = dep.imports; _i < _a.length; _i++) { - var impt = _a[_i]; - impt.imported = _this.getVariableExportName(oldExportNames[impt.imported]); - } - } - if (dep.reexports) { - for (var _b = 0, _c = dep.reexports; _b < _c.length; _b++) { - var reexport = _c[_b]; - reexport.imported = _this.getVariableExportName(oldExportNames[reexport.imported]); - } - } - }; - var mergeRenderedDeclaration = function (into, from) { - if (from.imports) { - if (!into.imports) { - into.imports = from.imports; - } - else { - into.imports = into.imports.concat(from.imports); - } - } - if (from.reexports) { - if (!into.reexports) { - into.reexports = from.reexports; - } - else { - into.reexports = into.reexports.concat(from.reexports); - } - } - if (!into.exportsNames && from.exportsNames) { - into.exportsNames = true; - } - if (!into.exportsDefault && from.exportsDefault) { - into.exportsDefault = true; - } - into.name = _this.name; - }; - // go through the other chunks and update their dependencies - // also update their import and reexport names in the process - for (var _h = 0, chunkList_1 = chunkList; _h < chunkList_1.length; _h++) { - var c = chunkList_1[_h]; - var includedDeclaration = void 0; - for (var i = 0; i < c.dependencies.length; i++) { - var dep = c.dependencies[i]; - if ((dep === chunk || dep === this) && includedDeclaration) { - var duplicateDeclaration = c.renderedDeclarations.dependencies[i]; - updateRenderedDeclaration(duplicateDeclaration, dep === chunk ? chunk.exportNames : thisOldExportNames); - mergeRenderedDeclaration(includedDeclaration, duplicateDeclaration); - c.renderedDeclarations.dependencies.splice(i, 1); - c.dependencies.splice(i--, 1); - } - else if (dep === chunk) { - c.dependencies[i] = this; - includedDeclaration = c.renderedDeclarations.dependencies[i]; - updateRenderedDeclaration(includedDeclaration, chunk.exportNames); - } - else if (dep === this) { - includedDeclaration = c.renderedDeclarations.dependencies[i]; - updateRenderedDeclaration(includedDeclaration, thisOldExportNames); - } - } - } - // re-render the merged chunk - this.preRender(options, inputBase); - }; - Chunk.prototype.generateIdPreserveModules = function (preserveModulesRelativeDir) { - return (this.id = normalize(relative(preserveModulesRelativeDir, this.entryModule.id))); - }; - Chunk.prototype.generateId = function (pattern, patternName, addons, options, existingNames) { - var _this = this; - var outName = makeUnique(renderNamePattern(pattern, patternName, function (type) { - switch (type) { - case 'hash': - return _this.computeFullHash(addons, options); - case 'name': - if (_this.entryModule && _this.entryModule.chunkAlias) - return _this.entryModule.chunkAlias; - for (var _i = 0, _a = _this.orderedModules; _i < _a.length; _i++) { - var module = _a[_i]; - if (module.chunkAlias) - return module.chunkAlias; - } - return 'chunk'; - } - }), existingNames); - this.id = outName; - }; - Chunk.prototype.render = function (options, addons) { - var _this = this; - timeStart('render format', 3); - if (!this.renderedSource) - throw new Error('Internal error: Chunk render called before preRender'); - var finalise = finalisers[options.format]; - if (!finalise) { - error({ - code: 'INVALID_OPTION', - message: "Invalid format: " + options.format + " - valid options are " + Object.keys(finalisers).join(', ') - }); - } - // populate ids in the rendered declarations only here - // as chunk ids known only after prerender - for (var i = 0; i < this.dependencies.length; i++) { - var dep = this.dependencies[i]; - if (dep instanceof ExternalModule && !dep.renormalizeRenderPath) - continue; - var renderedDependency = this.renderedDeclarations.dependencies[i]; - var depId = dep instanceof ExternalModule ? renderedDependency.id : dep.id; - var relPath = this.id ? normalize(relative(dirname(this.id), depId)) : depId; - if (!relPath.startsWith('../')) - relPath = './' + relPath; - if (dep instanceof Chunk) - renderedDependency.namedExportsMode = dep.exportMode !== 'default'; - renderedDependency.id = relPath; - } - this.finaliseDynamicImports(); - var needsAmdModule = this.finaliseImportMetas(options); - var hasExports = this.renderedDeclarations.exports.length !== 0 || - this.renderedDeclarations.dependencies.some(function (dep) { return dep.reexports && dep.reexports.length !== 0; }); - var usesTopLevelAwait = this.orderedModules.some(function (module) { return module.usesTopLevelAwait; }); - if (usesTopLevelAwait && options.format !== 'es' && options.format !== 'system') { - error({ - code: 'INVALID_TLA_FORMAT', - message: "Module format " + options.format + " does not support top-level await. Use the \"es\" or \"system\" output formats rather." - }); - } - var magicString = finalise(this.renderedSource, { - indentString: this.indentString, - namedExportsMode: this.exportMode !== 'default', - hasExports: hasExports, - intro: addons.intro, - outro: addons.outro, - dynamicImport: this.hasDynamicImport, - needsAmdModule: needsAmdModule, - dependencies: this.renderedDeclarations.dependencies, - exports: this.renderedDeclarations.exports, - graph: this.graph, - isEntryModuleFacade: this.isEntryModuleFacade, - usesTopLevelAwait: usesTopLevelAwait - }, options); - if (addons.banner) - magicString.prepend(addons.banner); - if (addons.footer) - magicString.append(addons.footer); - var prevCode = magicString.toString(); - timeEnd('render format', 3); - var map = null; - var chunkSourcemapChain = []; - return transformChunk(this.graph, this, prevCode, chunkSourcemapChain, options).then(function (code) { - if (options.sourcemap) { - timeStart('sourcemap', 3); - var file = void 0; - if (options.file) - file = resolve(options.sourcemapFile || options.file); - else if (options.dir) - file = resolve(options.dir, _this.id); - else - file = resolve(_this.id); - if (_this.graph.hasLoaders || - _this.graph.plugins.find(function (plugin) { return Boolean(plugin.transform || plugin.transformBundle); })) { - var decodedMap = magicString.generateDecodedMap({}); - map = collapseSourcemaps(_this, file, decodedMap, _this.usedModules, chunkSourcemapChain); - } - else { - map = magicString.generateMap({ file: file, includeContent: true }); - } - map.sources = map.sources.map(normalize); - timeEnd('sourcemap', 3); - } - if (options.compact !== true && code[code.length - 1] !== '\n') - code += '\n'; - return { code: code, map: map }; - }); - }; - return Chunk; - }()); - - /* - * Given a chunk list, perform optimizations on that chunk list - * to reduce the mumber of chunks. Mutates the chunks array. - * - * Manual chunks (with chunk.chunkAlias already set) are preserved - * Entry points are carefully preserved as well - * - */ - function optimizeChunks(chunks, options, CHUNK_GROUPING_SIZE, inputBase) { - var _loop_1 = function (chunkIndex) { - var mainChunk = chunks[chunkIndex]; - var execGroup = []; - mainChunk.postVisitChunkDependencies(function (dep) { - if (dep instanceof Chunk$1) { - execGroup.push(dep); - } - }); - if (execGroup.length < 2) { - return out_chunkIndex_1 = chunkIndex, "continue"; - } - var execGroupIndex = 1; - var seekingFirstMergeCandidate = true; - var lastChunk, chunk = execGroup[0], nextChunk = execGroup[1]; - var isMergeCandidate = function (chunk) { - if (chunk.isEntryModuleFacade || chunk.isManualChunk) { - return false; - } - if (!nextChunk || nextChunk.isEntryModuleFacade) { - return false; - } - if (chunk.getRenderedSourceLength() > CHUNK_GROUPING_SIZE) { - return false; - } - // if (!chunk.isPure()) continue; - return true; - }; - var _loop_2 = function () { - if (seekingFirstMergeCandidate) { - if (isMergeCandidate(chunk)) { - seekingFirstMergeCandidate = false; - } - return "continue"; - } - var remainingSize = CHUNK_GROUPING_SIZE - lastChunk.getRenderedSourceLength() - chunk.getRenderedSourceLength(); - if (remainingSize <= 0) { - if (!isMergeCandidate(chunk)) { - seekingFirstMergeCandidate = true; - } - return "continue"; - } - // if (!chunk.isPure()) continue; - var chunkDependencies = new Set(); - chunk.postVisitChunkDependencies(function (dep) { return chunkDependencies.add(dep); }); - var ignoreSizeChunks = new Set([chunk, lastChunk]); - if (lastChunk.postVisitChunkDependencies(function (dep) { - if (dep === chunk || dep === lastChunk) { - return false; - } - if (chunkDependencies.has(dep)) { - return false; - } - if (dep instanceof ExternalModule) { - return true; - } - remainingSize -= dep.getRenderedSourceLength(); - if (remainingSize <= 0) { - return true; - } - ignoreSizeChunks.add(dep); - })) { - if (!isMergeCandidate(chunk)) { - seekingFirstMergeCandidate = true; - } - return "continue"; - } - if (chunk.postVisitChunkDependencies(function (dep) { - if (ignoreSizeChunks.has(dep)) { - return false; - } - if (dep instanceof ExternalModule) { - return true; - } - remainingSize -= dep.getRenderedSourceLength(); - if (remainingSize <= 0) { - return true; - } - })) { - if (!isMergeCandidate(chunk)) { - seekingFirstMergeCandidate = true; - } - return "continue"; - } - // within the size limit -> merge! - var optimizedChunkIndex = chunks.indexOf(chunk); - if (optimizedChunkIndex <= chunkIndex) - chunkIndex--; - chunks.splice(optimizedChunkIndex, 1); - lastChunk.merge(chunk, chunks, options, inputBase); - execGroup.splice(--execGroupIndex, 1); - chunk = lastChunk; - // keep going to see if we can merge this with the next again - if (nextChunk && !isMergeCandidate(nextChunk)) { - seekingFirstMergeCandidate = true; - } - }; - do { - _loop_2(); - } while (((lastChunk = chunk), (chunk = nextChunk), (nextChunk = execGroup[++execGroupIndex]), chunk)); - out_chunkIndex_1 = chunkIndex; - }; - var out_chunkIndex_1; - for (var chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) { - _loop_1(chunkIndex); - chunkIndex = out_chunkIndex_1; - } - return chunks; - } - - // Reserved word lists for various dialects of the language - - var reservedWords$1 = { - 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile", - 5: "class enum extends super const export import", - 6: "enum", - strict: "implements interface let package private protected public static yield", - strictBind: "eval arguments" - }; - - // And the keywords - - var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this"; - - var keywords = { - 5: ecma5AndLessKeywords, - 6: ecma5AndLessKeywords + " const class extends export import super" - }; - - var keywordRelationalOperator = /^in(stanceof)?$/; - - // ## Character categories - - // Big ugly regular expressions that match characters in the - // whitespace, identifier, and identifier-start categories. These - // are only applied when a character is found to actually have a - // code point above 128. - // Generated by `bin/generate-identifier-regex.js`. - - var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fef\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7b9\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab65\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc"; - var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f"; - - var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]"); - var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]"); - - nonASCIIidentifierStartChars = nonASCIIidentifierChars = null; - - // These are a run-length and offset encoded representation of the - // >0xffff code points that are a valid part of identifiers. The - // offset starts at 0x10000, and each pair of numbers represents an - // offset to the next range, and then a size of the range. They were - // generated by bin/generate-identifier-regex.js - - // eslint-disable-next-line comma-spacing - var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,477,28,11,0,9,21,190,52,76,44,33,24,27,35,30,0,12,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,26,230,43,117,63,32,0,257,0,11,39,8,0,22,0,12,39,3,3,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,270,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,68,12,0,67,12,65,1,31,6129,15,754,9486,286,82,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,15,7472,3104,541]; - - // eslint-disable-next-line comma-spacing - var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,525,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,4,9,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,280,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239]; - - // This has a complexity linear to the value of the code. The - // assumption is that looking up astral identifier characters is - // rare. - function isInAstralSet(code, set) { - var pos = 0x10000; - for (var i = 0; i < set.length; i += 2) { - pos += set[i]; - if (pos > code) { return false } - pos += set[i + 1]; - if (pos >= code) { return true } - } - } - - // Test whether a given character code starts an identifier. - - function isIdentifierStart(code, astral) { - if (code < 65) { return code === 36 } - if (code < 91) { return true } - if (code < 97) { return code === 95 } - if (code < 123) { return true } - if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) } - if (astral === false) { return false } - return isInAstralSet(code, astralIdentifierStartCodes) - } - - // Test whether a given character is part of an identifier. - - function isIdentifierChar(code, astral) { - if (code < 48) { return code === 36 } - if (code < 58) { return true } - if (code < 65) { return false } - if (code < 91) { return true } - if (code < 97) { return code === 95 } - if (code < 123) { return true } - if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) } - if (astral === false) { return false } - return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes) - } - - // ## Token types - - // The assignment of fine-grained, information-carrying type objects - // allows the tokenizer to store the information it has about a - // token in a way that is very cheap for the parser to look up. - - // All token type variables start with an underscore, to make them - // easy to recognize. - - // The `beforeExpr` property is used to disambiguate between regular - // expressions and divisions. It is set on all token types that can - // be followed by an expression (thus, a slash after them would be a - // regular expression). - // - // The `startsExpr` property is used to check if the token ends a - // `yield` expression. It is set on all token types that either can - // directly start an expression (like a quotation mark) or can - // continue an expression (like the body of a string). - // - // `isLoop` marks a keyword as starting a loop, which is important - // to know when parsing a label, in order to allow or disallow - // continue jumps to that label. - - var TokenType = function TokenType(label, conf) { - if ( conf === void 0 ) conf = {}; - - this.label = label; - this.keyword = conf.keyword; - this.beforeExpr = !!conf.beforeExpr; - this.startsExpr = !!conf.startsExpr; - this.isLoop = !!conf.isLoop; - this.isAssign = !!conf.isAssign; - this.prefix = !!conf.prefix; - this.postfix = !!conf.postfix; - this.binop = conf.binop || null; - this.updateContext = null; - }; - - function binop(name, prec) { - return new TokenType(name, {beforeExpr: true, binop: prec}) - } - var beforeExpr = {beforeExpr: true}; - var startsExpr = {startsExpr: true}; - - // Map keyword names to token types. - - var keywords$1 = {}; - - // Succinct definitions of keyword token types - function kw(name, options) { - if ( options === void 0 ) options = {}; - - options.keyword = name; - return keywords$1[name] = new TokenType(name, options) - } - - var types = { - num: new TokenType("num", startsExpr), - regexp: new TokenType("regexp", startsExpr), - string: new TokenType("string", startsExpr), - name: new TokenType("name", startsExpr), - eof: new TokenType("eof"), - - // Punctuation token types. - bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}), - bracketR: new TokenType("]"), - braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}), - braceR: new TokenType("}"), - parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}), - parenR: new TokenType(")"), - comma: new TokenType(",", beforeExpr), - semi: new TokenType(";", beforeExpr), - colon: new TokenType(":", beforeExpr), - dot: new TokenType("."), - question: new TokenType("?", beforeExpr), - arrow: new TokenType("=>", beforeExpr), - template: new TokenType("template"), - invalidTemplate: new TokenType("invalidTemplate"), - ellipsis: new TokenType("...", beforeExpr), - backQuote: new TokenType("`", startsExpr), - dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}), - - // Operators. These carry several kinds of properties to help the - // parser use them properly (the presence of these properties is - // what categorizes them as operators). - // - // `binop`, when present, specifies that this operator is a binary - // operator, and will refer to its precedence. - // - // `prefix` and `postfix` mark the operator as a prefix or postfix - // unary operator. - // - // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as - // binary operators with a very low precedence, that should result - // in AssignmentExpression nodes. - - eq: new TokenType("=", {beforeExpr: true, isAssign: true}), - assign: new TokenType("_=", {beforeExpr: true, isAssign: true}), - incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}), - prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}), - logicalOR: binop("||", 1), - logicalAND: binop("&&", 2), - bitwiseOR: binop("|", 3), - bitwiseXOR: binop("^", 4), - bitwiseAND: binop("&", 5), - equality: binop("==/!=/===/!==", 6), - relational: binop("/<=/>=", 7), - bitShift: binop("<>/>>>", 8), - plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}), - modulo: binop("%", 10), - star: binop("*", 10), - slash: binop("/", 10), - starstar: new TokenType("**", {beforeExpr: true}), - - // Keyword token types. - _break: kw("break"), - _case: kw("case", beforeExpr), - _catch: kw("catch"), - _continue: kw("continue"), - _debugger: kw("debugger"), - _default: kw("default", beforeExpr), - _do: kw("do", {isLoop: true, beforeExpr: true}), - _else: kw("else", beforeExpr), - _finally: kw("finally"), - _for: kw("for", {isLoop: true}), - _function: kw("function", startsExpr), - _if: kw("if"), - _return: kw("return", beforeExpr), - _switch: kw("switch"), - _throw: kw("throw", beforeExpr), - _try: kw("try"), - _var: kw("var"), - _const: kw("const"), - _while: kw("while", {isLoop: true}), - _with: kw("with"), - _new: kw("new", {beforeExpr: true, startsExpr: true}), - _this: kw("this", startsExpr), - _super: kw("super", startsExpr), - _class: kw("class", startsExpr), - _extends: kw("extends", beforeExpr), - _export: kw("export"), - _import: kw("import"), - _null: kw("null", startsExpr), - _true: kw("true", startsExpr), - _false: kw("false", startsExpr), - _in: kw("in", {beforeExpr: true, binop: 7}), - _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}), - _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}), - _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}), - _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true}) - }; - - // Matches a whole line break (where CRLF is considered a single - // line break). Used to count lines. - - var lineBreak = /\r\n?|\n|\u2028|\u2029/; - var lineBreakG = new RegExp(lineBreak.source, "g"); - - function isNewLine(code, ecma2019String) { - return code === 10 || code === 13 || (!ecma2019String && (code === 0x2028 || code === 0x2029)) - } - - var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/; - - var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g; - - var ref = Object.prototype; - var hasOwnProperty = ref.hasOwnProperty; - var toString$1 = ref.toString; - - // Checks if an object has a property. - - function has(obj, propName) { - return hasOwnProperty.call(obj, propName) - } - - var isArray = Array.isArray || (function (obj) { return ( - toString$1.call(obj) === "[object Array]" - ); }); - - // These are used when `options.locations` is on, for the - // `startLoc` and `endLoc` properties. - - var Position = function Position(line, col) { - this.line = line; - this.column = col; - }; - - Position.prototype.offset = function offset (n) { - return new Position(this.line, this.column + n) - }; - - var SourceLocation = function SourceLocation(p, start, end) { - this.start = start; - this.end = end; - if (p.sourceFile !== null) { this.source = p.sourceFile; } - }; - - // The `getLineInfo` function is mostly useful when the - // `locations` option is off (for performance reasons) and you - // want to find the line/column position for a given character - // offset. `input` should be the code string that the offset refers - // into. - - function getLineInfo(input, offset) { - for (var line = 1, cur = 0;;) { - lineBreakG.lastIndex = cur; - var match = lineBreakG.exec(input); - if (match && match.index < offset) { - ++line; - cur = match.index + match[0].length; - } else { - return new Position(line, offset - cur) - } - } - } - - // A second optional argument can be given to further configure - // the parser process. These options are recognized: - - var defaultOptions = { - // `ecmaVersion` indicates the ECMAScript version to parse. Must - // be either 3, 5, 6 (2015), 7 (2016), or 8 (2017). This influences support - // for strict mode, the set of reserved words, and support for - // new syntax features. The default is 7. - ecmaVersion: 7, - // `sourceType` indicates the mode the code should be parsed in. - // Can be either `"script"` or `"module"`. This influences global - // strict mode and parsing of `import` and `export` declarations. - sourceType: "script", - // `onInsertedSemicolon` can be a callback that will be called - // when a semicolon is automatically inserted. It will be passed - // th position of the comma as an offset, and if `locations` is - // enabled, it is given the location as a `{line, column}` object - // as second argument. - onInsertedSemicolon: null, - // `onTrailingComma` is similar to `onInsertedSemicolon`, but for - // trailing commas. - onTrailingComma: null, - // By default, reserved words are only enforced if ecmaVersion >= 5. - // Set `allowReserved` to a boolean value to explicitly turn this on - // an off. When this option has the value "never", reserved words - // and keywords can also not be used as property names. - allowReserved: null, - // When enabled, a return at the top level is not considered an - // error. - allowReturnOutsideFunction: false, - // When enabled, import/export statements are not constrained to - // appearing at the top of the program. - allowImportExportEverywhere: false, - // When enabled, await identifiers are allowed to appear at the top-level scope, - // but they are still not allowed in non-async functions. - allowAwaitOutsideFunction: false, - // When enabled, hashbang directive in the beginning of file - // is allowed and treated as a line comment. - allowHashBang: false, - // When `locations` is on, `loc` properties holding objects with - // `start` and `end` properties in `{line, column}` form (with - // line being 1-based and column 0-based) will be attached to the - // nodes. - locations: false, - // A function can be passed as `onToken` option, which will - // cause Acorn to call that function with object in the same - // format as tokens returned from `tokenizer().getToken()`. Note - // that you are not allowed to call the parser from the - // callback—that will corrupt its internal state. - onToken: null, - // A function can be passed as `onComment` option, which will - // cause Acorn to call that function with `(block, text, start, - // end)` parameters whenever a comment is skipped. `block` is a - // boolean indicating whether this is a block (`/* */`) comment, - // `text` is the content of the comment, and `start` and `end` are - // character offsets that denote the start and end of the comment. - // When the `locations` option is on, two more parameters are - // passed, the full `{line, column}` locations of the start and - // end of the comments. Note that you are not allowed to call the - // parser from the callback—that will corrupt its internal state. - onComment: null, - // Nodes have their start and end characters offsets recorded in - // `start` and `end` properties (directly on the node, rather than - // the `loc` object, which holds line/column data. To also add a - // [semi-standardized][range] `range` property holding a `[start, - // end]` array with the same numbers, set the `ranges` option to - // `true`. - // - // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678 - ranges: false, - // It is possible to parse multiple files into a single AST by - // passing the tree produced by parsing the first file as - // `program` option in subsequent parses. This will add the - // toplevel forms of the parsed file to the `Program` (top) node - // of an existing parse tree. - program: null, - // When `locations` is on, you can pass this to record the source - // file in every node's `loc` object. - sourceFile: null, - // This value, if given, is stored in every node, whether - // `locations` is on or off. - directSourceFile: null, - // When enabled, parenthesized expressions are represented by - // (non-standard) ParenthesizedExpression nodes - preserveParens: false, - plugins: {} - }; - - // Interpret and default an options object - - function getOptions(opts) { - var options = {}; - - for (var opt in defaultOptions) - { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; } - - if (options.ecmaVersion >= 2015) - { options.ecmaVersion -= 2009; } - - if (options.allowReserved == null) - { options.allowReserved = options.ecmaVersion < 5; } - - if (isArray(options.onToken)) { - var tokens = options.onToken; - options.onToken = function (token) { return tokens.push(token); }; - } - if (isArray(options.onComment)) - { options.onComment = pushComment(options, options.onComment); } - - return options - } - - function pushComment(options, array) { - return function(block, text, start, end, startLoc, endLoc) { - var comment = { - type: block ? "Block" : "Line", - value: text, - start: start, - end: end - }; - if (options.locations) - { comment.loc = new SourceLocation(this, startLoc, endLoc); } - if (options.ranges) - { comment.range = [start, end]; } - array.push(comment); - } - } - - // Registered plugins - var plugins = {}; - - function keywordRegexp(words) { - return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$") - } - - var Parser = function Parser(options, input, startPos) { - this.options = options = getOptions(options); - this.sourceFile = options.sourceFile; - this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]); - var reserved = ""; - if (!options.allowReserved) { - for (var v = options.ecmaVersion;; v--) - { if (reserved = reservedWords$1[v]) { break } } - if (options.sourceType === "module") { reserved += " await"; } - } - this.reservedWords = keywordRegexp(reserved); - var reservedStrict = (reserved ? reserved + " " : "") + reservedWords$1.strict; - this.reservedWordsStrict = keywordRegexp(reservedStrict); - this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords$1.strictBind); - this.input = String(input); - - // Used to signal to callers of `readWord1` whether the word - // contained any escape sequences. This is needed because words with - // escape sequences must not be interpreted as keywords. - this.containsEsc = false; - - // Load plugins - this.loadPlugins(options.plugins); - - // Set up token state - - // The current position of the tokenizer in the input. - if (startPos) { - this.pos = startPos; - this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1; - this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length; - } else { - this.pos = this.lineStart = 0; - this.curLine = 1; - } - - // Properties of the current token: - // Its type - this.type = types.eof; - // For tokens that include more information than their type, the value - this.value = null; - // Its start and end offset - this.start = this.end = this.pos; - // And, if locations are used, the {line, column} object - // corresponding to those offsets - this.startLoc = this.endLoc = this.curPosition(); - - // Position information for the previous token - this.lastTokEndLoc = this.lastTokStartLoc = null; - this.lastTokStart = this.lastTokEnd = this.pos; - - // The context stack is used to superficially track syntactic - // context to predict whether a regular expression is allowed in a - // given position. - this.context = this.initialContext(); - this.exprAllowed = true; - - // Figure out if it's a module code. - this.inModule = options.sourceType === "module"; - this.strict = this.inModule || this.strictDirective(this.pos); - - // Used to signify the start of a potential arrow function - this.potentialArrowAt = -1; - - // Flags to track whether we are in a function, a generator, an async function. - this.inFunction = this.inGenerator = this.inAsync = false; - // Positions to delayed-check that yield/await does not exist in default parameters. - this.yieldPos = this.awaitPos = 0; - // Labels in scope. - this.labels = []; - - // If enabled, skip leading hashbang line. - if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!") - { this.skipLineComment(2); } - - // Scope tracking for duplicate variable names (see scope.js) - this.scopeStack = []; - this.enterFunctionScope(); - - // For RegExp validation - this.regexpState = null; - }; - - // DEPRECATED Kept for backwards compatibility until 3.0 in case a plugin uses them - Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) }; - Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) }; - - Parser.prototype.extend = function extend (name, f) { - this[name] = f(this[name]); - }; - - Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) { - var this$1 = this; - - for (var name in pluginConfigs) { - var plugin = plugins[name]; - if (!plugin) { throw new Error("Plugin '" + name + "' not found") } - plugin(this$1, pluginConfigs[name]); - } - }; - - Parser.prototype.parse = function parse () { - var node = this.options.program || this.startNode(); - this.nextToken(); - return this.parseTopLevel(node) - }; - - var pp = Parser.prototype; - - // ## Parser utilities - - var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/; - pp.strictDirective = function(start) { - var this$1 = this; - - for (;;) { - skipWhiteSpace.lastIndex = start; - start += skipWhiteSpace.exec(this$1.input)[0].length; - var match = literal.exec(this$1.input.slice(start)); - if (!match) { return false } - if ((match[1] || match[2]) === "use strict") { return true } - start += match[0].length; - } - }; - - // Predicate that tests whether the next token is of the given - // type, and if yes, consumes it as a side effect. - - pp.eat = function(type) { - if (this.type === type) { - this.next(); - return true - } else { - return false - } - }; - - // Tests whether parsed token is a contextual keyword. - - pp.isContextual = function(name) { - return this.type === types.name && this.value === name && !this.containsEsc - }; - - // Consumes contextual keyword if possible. - - pp.eatContextual = function(name) { - if (!this.isContextual(name)) { return false } - this.next(); - return true - }; - - // Asserts that following token is given contextual keyword. - - pp.expectContextual = function(name) { - if (!this.eatContextual(name)) { this.unexpected(); } - }; - - // Test whether a semicolon can be inserted at the current position. - - pp.canInsertSemicolon = function() { - return this.type === types.eof || - this.type === types.braceR || - lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) - }; - - pp.insertSemicolon = function() { - if (this.canInsertSemicolon()) { - if (this.options.onInsertedSemicolon) - { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); } - return true - } - }; - - // Consume a semicolon, or, failing that, see if we are allowed to - // pretend that there is a semicolon at this position. - - pp.semicolon = function() { - if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); } - }; - - pp.afterTrailingComma = function(tokType, notNext) { - if (this.type === tokType) { - if (this.options.onTrailingComma) - { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); } - if (!notNext) - { this.next(); } - return true - } - }; - - // Expect a token of a given type. If found, consume it, otherwise, - // raise an unexpected token error. - - pp.expect = function(type) { - this.eat(type) || this.unexpected(); - }; - - // Raise an unexpected token error. - - pp.unexpected = function(pos) { - this.raise(pos != null ? pos : this.start, "Unexpected token"); - }; - - function DestructuringErrors() { - this.shorthandAssign = - this.trailingComma = - this.parenthesizedAssign = - this.parenthesizedBind = - this.doubleProto = - -1; - } - - pp.checkPatternErrors = function(refDestructuringErrors, isAssign) { - if (!refDestructuringErrors) { return } - if (refDestructuringErrors.trailingComma > -1) - { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); } - var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind; - if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); } - }; - - pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) { - if (!refDestructuringErrors) { return false } - var shorthandAssign = refDestructuringErrors.shorthandAssign; - var doubleProto = refDestructuringErrors.doubleProto; - if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 } - if (shorthandAssign >= 0) - { this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); } - if (doubleProto >= 0) - { this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); } - }; - - pp.checkYieldAwaitInDefaultParams = function() { - if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos)) - { this.raise(this.yieldPos, "Yield expression cannot be a default value"); } - if (this.awaitPos) - { this.raise(this.awaitPos, "Await expression cannot be a default value"); } - }; - - pp.isSimpleAssignTarget = function(expr) { - if (expr.type === "ParenthesizedExpression") - { return this.isSimpleAssignTarget(expr.expression) } - return expr.type === "Identifier" || expr.type === "MemberExpression" - }; - - var pp$1 = Parser.prototype; - - // ### Statement parsing - - // Parse a program. Initializes the parser, reads any number of - // statements, and wraps them in a Program node. Optionally takes a - // `program` argument. If present, the statements will be appended - // to its body instead of creating a new node. - - pp$1.parseTopLevel = function(node) { - var this$1 = this; - - var exports = {}; - if (!node.body) { node.body = []; } - while (this.type !== types.eof) { - var stmt = this$1.parseStatement(true, true, exports); - node.body.push(stmt); - } - this.adaptDirectivePrologue(node.body); - this.next(); - if (this.options.ecmaVersion >= 6) { - node.sourceType = this.options.sourceType; - } - return this.finishNode(node, "Program") - }; - - var loopLabel = {kind: "loop"}; - var switchLabel = {kind: "switch"}; - - pp$1.isLet = function() { - if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false } - skipWhiteSpace.lastIndex = this.pos; - var skip = skipWhiteSpace.exec(this.input); - var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next); - if (nextCh === 91 || nextCh === 123) { return true } // '{' and '[' - if (isIdentifierStart(nextCh, true)) { - var pos = next + 1; - while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; } - var ident = this.input.slice(next, pos); - if (!keywordRelationalOperator.test(ident)) { return true } - } - return false - }; - - // check 'async [no LineTerminator here] function' - // - 'async /*foo*/ function' is OK. - // - 'async /*\n*/ function' is invalid. - pp$1.isAsyncFunction = function() { - if (this.options.ecmaVersion < 8 || !this.isContextual("async")) - { return false } - - skipWhiteSpace.lastIndex = this.pos; - var skip = skipWhiteSpace.exec(this.input); - var next = this.pos + skip[0].length; - return !lineBreak.test(this.input.slice(this.pos, next)) && - this.input.slice(next, next + 8) === "function" && - (next + 8 === this.input.length || !isIdentifierChar(this.input.charAt(next + 8))) - }; - - // Parse a single statement. - // - // If expecting a statement and finding a slash operator, parse a - // regular expression literal. This is to handle cases like - // `if (foo) /blah/.exec(foo)`, where looking at the previous token - // does not help. - - pp$1.parseStatement = function(declaration, topLevel, exports) { - var starttype = this.type, node = this.startNode(), kind; - - if (this.isLet()) { - starttype = types._var; - kind = "let"; - } - - // Most types of statements are recognized by the keyword they - // start with. Many are trivial to parse, some require a bit of - // complexity. - - switch (starttype) { - case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword) - case types._debugger: return this.parseDebuggerStatement(node) - case types._do: return this.parseDoStatement(node) - case types._for: return this.parseForStatement(node) - case types._function: - if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); } - return this.parseFunctionStatement(node, false) - case types._class: - if (!declaration) { this.unexpected(); } - return this.parseClass(node, true) - case types._if: return this.parseIfStatement(node) - case types._return: return this.parseReturnStatement(node) - case types._switch: return this.parseSwitchStatement(node) - case types._throw: return this.parseThrowStatement(node) - case types._try: return this.parseTryStatement(node) - case types._const: case types._var: - kind = kind || this.value; - if (!declaration && kind !== "var") { this.unexpected(); } - return this.parseVarStatement(node, kind) - case types._while: return this.parseWhileStatement(node) - case types._with: return this.parseWithStatement(node) - case types.braceL: return this.parseBlock() - case types.semi: return this.parseEmptyStatement(node) - case types._export: - case types._import: - if (!this.options.allowImportExportEverywhere) { - if (!topLevel) - { this.raise(this.start, "'import' and 'export' may only appear at the top level"); } - if (!this.inModule) - { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); } - } - return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports) - - // If the statement does not start with a statement keyword or a - // brace, it's an ExpressionStatement or LabeledStatement. We - // simply start parsing an expression, and afterwards, if the - // next token is a colon and the expression was a simple - // Identifier node, we switch to interpreting it as a label. - default: - if (this.isAsyncFunction()) { - if (!declaration) { this.unexpected(); } - this.next(); - return this.parseFunctionStatement(node, true) - } - - var maybeName = this.value, expr = this.parseExpression(); - if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon)) - { return this.parseLabeledStatement(node, maybeName, expr) } - else { return this.parseExpressionStatement(node, expr) } - } - }; - - pp$1.parseBreakContinueStatement = function(node, keyword) { - var this$1 = this; - - var isBreak = keyword === "break"; - this.next(); - if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; } - else if (this.type !== types.name) { this.unexpected(); } - else { - node.label = this.parseIdent(); - this.semicolon(); - } - - // Verify that there is an actual destination to break or - // continue to. - var i = 0; - for (; i < this.labels.length; ++i) { - var lab = this$1.labels[i]; - if (node.label == null || lab.name === node.label.name) { - if (lab.kind != null && (isBreak || lab.kind === "loop")) { break } - if (node.label && isBreak) { break } - } - } - if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); } - return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement") - }; - - pp$1.parseDebuggerStatement = function(node) { - this.next(); - this.semicolon(); - return this.finishNode(node, "DebuggerStatement") - }; - - pp$1.parseDoStatement = function(node) { - this.next(); - this.labels.push(loopLabel); - node.body = this.parseStatement(false); - this.labels.pop(); - this.expect(types._while); - node.test = this.parseParenExpression(); - if (this.options.ecmaVersion >= 6) - { this.eat(types.semi); } - else - { this.semicolon(); } - return this.finishNode(node, "DoWhileStatement") - }; - - // Disambiguating between a `for` and a `for`/`in` or `for`/`of` - // loop is non-trivial. Basically, we have to parse the init `var` - // statement or expression, disallowing the `in` operator (see - // the second parameter to `parseExpression`), and then check - // whether the next token is `in` or `of`. When there is no init - // part (semicolon immediately after the opening parenthesis), it - // is a regular `for` loop. - - pp$1.parseForStatement = function(node) { - this.next(); - var awaitAt = (this.options.ecmaVersion >= 9 && this.inAsync && this.eatContextual("await")) ? this.lastTokStart : -1; - this.labels.push(loopLabel); - this.enterLexicalScope(); - this.expect(types.parenL); - if (this.type === types.semi) { - if (awaitAt > -1) { this.unexpected(awaitAt); } - return this.parseFor(node, null) - } - var isLet = this.isLet(); - if (this.type === types._var || this.type === types._const || isLet) { - var init$1 = this.startNode(), kind = isLet ? "let" : this.value; - this.next(); - this.parseVar(init$1, true, kind); - this.finishNode(init$1, "VariableDeclaration"); - if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 && - !(kind !== "var" && init$1.declarations[0].init)) { - if (this.options.ecmaVersion >= 9) { - if (this.type === types._in) { - if (awaitAt > -1) { this.unexpected(awaitAt); } - } else { node.await = awaitAt > -1; } - } - return this.parseForIn(node, init$1) - } - if (awaitAt > -1) { this.unexpected(awaitAt); } - return this.parseFor(node, init$1) - } - var refDestructuringErrors = new DestructuringErrors; - var init = this.parseExpression(true, refDestructuringErrors); - if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) { - if (this.options.ecmaVersion >= 9) { - if (this.type === types._in) { - if (awaitAt > -1) { this.unexpected(awaitAt); } - } else { node.await = awaitAt > -1; } - } - this.toAssignable(init, false, refDestructuringErrors); - this.checkLVal(init); - return this.parseForIn(node, init) - } else { - this.checkExpressionErrors(refDestructuringErrors, true); - } - if (awaitAt > -1) { this.unexpected(awaitAt); } - return this.parseFor(node, init) - }; - - pp$1.parseFunctionStatement = function(node, isAsync) { - this.next(); - return this.parseFunction(node, true, false, isAsync) - }; - - pp$1.parseIfStatement = function(node) { - this.next(); - node.test = this.parseParenExpression(); - // allow function declarations in branches, but only in non-strict mode - node.consequent = this.parseStatement(!this.strict && this.type === types._function); - node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.type === types._function) : null; - return this.finishNode(node, "IfStatement") - }; - - pp$1.parseReturnStatement = function(node) { - if (!this.inFunction && !this.options.allowReturnOutsideFunction) - { this.raise(this.start, "'return' outside of function"); } - this.next(); - - // In `return` (and `break`/`continue`), the keywords with - // optional arguments, we eagerly look for a semicolon or the - // possibility to insert one. - - if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; } - else { node.argument = this.parseExpression(); this.semicolon(); } - return this.finishNode(node, "ReturnStatement") - }; - - pp$1.parseSwitchStatement = function(node) { - var this$1 = this; - - this.next(); - node.discriminant = this.parseParenExpression(); - node.cases = []; - this.expect(types.braceL); - this.labels.push(switchLabel); - this.enterLexicalScope(); - - // Statements under must be grouped (by label) in SwitchCase - // nodes. `cur` is used to keep the node that we are currently - // adding statements to. - - var cur; - for (var sawDefault = false; this.type !== types.braceR;) { - if (this$1.type === types._case || this$1.type === types._default) { - var isCase = this$1.type === types._case; - if (cur) { this$1.finishNode(cur, "SwitchCase"); } - node.cases.push(cur = this$1.startNode()); - cur.consequent = []; - this$1.next(); - if (isCase) { - cur.test = this$1.parseExpression(); - } else { - if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); } - sawDefault = true; - cur.test = null; - } - this$1.expect(types.colon); - } else { - if (!cur) { this$1.unexpected(); } - cur.consequent.push(this$1.parseStatement(true)); - } - } - this.exitLexicalScope(); - if (cur) { this.finishNode(cur, "SwitchCase"); } - this.next(); // Closing brace - this.labels.pop(); - return this.finishNode(node, "SwitchStatement") - }; - - pp$1.parseThrowStatement = function(node) { - this.next(); - if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) - { this.raise(this.lastTokEnd, "Illegal newline after throw"); } - node.argument = this.parseExpression(); - this.semicolon(); - return this.finishNode(node, "ThrowStatement") - }; - - // Reused empty array added for node fields that are always empty. - - var empty = []; - - pp$1.parseTryStatement = function(node) { - this.next(); - node.block = this.parseBlock(); - node.handler = null; - if (this.type === types._catch) { - var clause = this.startNode(); - this.next(); - if (this.eat(types.parenL)) { - clause.param = this.parseBindingAtom(); - this.enterLexicalScope(); - this.checkLVal(clause.param, "let"); - this.expect(types.parenR); - } else { - if (this.options.ecmaVersion < 10) { this.unexpected(); } - clause.param = null; - this.enterLexicalScope(); - } - clause.body = this.parseBlock(false); - this.exitLexicalScope(); - node.handler = this.finishNode(clause, "CatchClause"); - } - node.finalizer = this.eat(types._finally) ? this.parseBlock() : null; - if (!node.handler && !node.finalizer) - { this.raise(node.start, "Missing catch or finally clause"); } - return this.finishNode(node, "TryStatement") - }; - - pp$1.parseVarStatement = function(node, kind) { - this.next(); - this.parseVar(node, false, kind); - this.semicolon(); - return this.finishNode(node, "VariableDeclaration") - }; - - pp$1.parseWhileStatement = function(node) { - this.next(); - node.test = this.parseParenExpression(); - this.labels.push(loopLabel); - node.body = this.parseStatement(false); - this.labels.pop(); - return this.finishNode(node, "WhileStatement") - }; - - pp$1.parseWithStatement = function(node) { - if (this.strict) { this.raise(this.start, "'with' in strict mode"); } - this.next(); - node.object = this.parseParenExpression(); - node.body = this.parseStatement(false); - return this.finishNode(node, "WithStatement") - }; - - pp$1.parseEmptyStatement = function(node) { - this.next(); - return this.finishNode(node, "EmptyStatement") - }; - - pp$1.parseLabeledStatement = function(node, maybeName, expr) { - var this$1 = this; - - for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1) - { - var label = list[i$1]; - - if (label.name === maybeName) - { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared"); - } } - var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null; - for (var i = this.labels.length - 1; i >= 0; i--) { - var label$1 = this$1.labels[i]; - if (label$1.statementStart === node.start) { - // Update information about previous labels on this node - label$1.statementStart = this$1.start; - label$1.kind = kind; - } else { break } - } - this.labels.push({name: maybeName, kind: kind, statementStart: this.start}); - node.body = this.parseStatement(true); - if (node.body.type === "ClassDeclaration" || - node.body.type === "VariableDeclaration" && node.body.kind !== "var" || - node.body.type === "FunctionDeclaration" && (this.strict || node.body.generator)) - { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); } - this.labels.pop(); - node.label = expr; - return this.finishNode(node, "LabeledStatement") - }; - - pp$1.parseExpressionStatement = function(node, expr) { - node.expression = expr; - this.semicolon(); - return this.finishNode(node, "ExpressionStatement") - }; - - // Parse a semicolon-enclosed block of statements, handling `"use - // strict"` declarations when `allowStrict` is true (used for - // function bodies). - - pp$1.parseBlock = function(createNewLexicalScope) { - var this$1 = this; - if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true; - - var node = this.startNode(); - node.body = []; - this.expect(types.braceL); - if (createNewLexicalScope) { - this.enterLexicalScope(); - } - while (!this.eat(types.braceR)) { - var stmt = this$1.parseStatement(true); - node.body.push(stmt); - } - if (createNewLexicalScope) { - this.exitLexicalScope(); - } - return this.finishNode(node, "BlockStatement") - }; - - // Parse a regular `for` loop. The disambiguation code in - // `parseStatement` will already have parsed the init statement or - // expression. - - pp$1.parseFor = function(node, init) { - node.init = init; - this.expect(types.semi); - node.test = this.type === types.semi ? null : this.parseExpression(); - this.expect(types.semi); - node.update = this.type === types.parenR ? null : this.parseExpression(); - this.expect(types.parenR); - this.exitLexicalScope(); - node.body = this.parseStatement(false); - this.labels.pop(); - return this.finishNode(node, "ForStatement") - }; - - // Parse a `for`/`in` and `for`/`of` loop, which are almost - // same from parser's perspective. - - pp$1.parseForIn = function(node, init) { - var type = this.type === types._in ? "ForInStatement" : "ForOfStatement"; - this.next(); - if (type === "ForInStatement") { - if (init.type === "AssignmentPattern" || - (init.type === "VariableDeclaration" && init.declarations[0].init != null && - (this.strict || init.declarations[0].id.type !== "Identifier"))) - { this.raise(init.start, "Invalid assignment in for-in loop head"); } - } - node.left = init; - node.right = type === "ForInStatement" ? this.parseExpression() : this.parseMaybeAssign(); - this.expect(types.parenR); - this.exitLexicalScope(); - node.body = this.parseStatement(false); - this.labels.pop(); - return this.finishNode(node, type) - }; - - // Parse a list of variable declarations. - - pp$1.parseVar = function(node, isFor, kind) { - var this$1 = this; - - node.declarations = []; - node.kind = kind; - for (;;) { - var decl = this$1.startNode(); - this$1.parseVarId(decl, kind); - if (this$1.eat(types.eq)) { - decl.init = this$1.parseMaybeAssign(isFor); - } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) { - this$1.unexpected(); - } else if (decl.id.type !== "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) { - this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value"); - } else { - decl.init = null; - } - node.declarations.push(this$1.finishNode(decl, "VariableDeclarator")); - if (!this$1.eat(types.comma)) { break } - } - return node - }; - - pp$1.parseVarId = function(decl, kind) { - decl.id = this.parseBindingAtom(kind); - this.checkLVal(decl.id, kind, false); - }; - - // Parse a function declaration or literal (depending on the - // `isStatement` parameter). - - pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) { - this.initFunction(node); - if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) - { node.generator = this.eat(types.star); } - if (this.options.ecmaVersion >= 8) - { node.async = !!isAsync; } - - if (isStatement) { - node.id = isStatement === "nullableID" && this.type !== types.name ? null : this.parseIdent(); - if (node.id) { - this.checkLVal(node.id, "var"); - } - } - - var oldInGen = this.inGenerator, oldInAsync = this.inAsync, - oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction; - this.inGenerator = node.generator; - this.inAsync = node.async; - this.yieldPos = 0; - this.awaitPos = 0; - this.inFunction = true; - this.enterFunctionScope(); - - if (!isStatement) - { node.id = this.type === types.name ? this.parseIdent() : null; } - - this.parseFunctionParams(node); - this.parseFunctionBody(node, allowExpressionBody); - - this.inGenerator = oldInGen; - this.inAsync = oldInAsync; - this.yieldPos = oldYieldPos; - this.awaitPos = oldAwaitPos; - this.inFunction = oldInFunc; - return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression") - }; - - pp$1.parseFunctionParams = function(node) { - this.expect(types.parenL); - node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8); - this.checkYieldAwaitInDefaultParams(); - }; - - // Parse a class declaration or literal (depending on the - // `isStatement` parameter). - - pp$1.parseClass = function(node, isStatement) { - var this$1 = this; - - this.next(); - - this.parseClassId(node, isStatement); - this.parseClassSuper(node); - var classBody = this.startNode(); - var hadConstructor = false; - classBody.body = []; - this.expect(types.braceL); - while (!this.eat(types.braceR)) { - var member = this$1.parseClassMember(classBody); - if (member && member.type === "MethodDefinition" && member.kind === "constructor") { - if (hadConstructor) { this$1.raise(member.start, "Duplicate constructor in the same class"); } - hadConstructor = true; - } - } - node.body = this.finishNode(classBody, "ClassBody"); - return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression") - }; - - pp$1.parseClassMember = function(classBody) { - var this$1 = this; - - if (this.eat(types.semi)) { return null } - - var method = this.startNode(); - var tryContextual = function (k, noLineBreak) { - if ( noLineBreak === void 0 ) noLineBreak = false; - - var start = this$1.start, startLoc = this$1.startLoc; - if (!this$1.eatContextual(k)) { return false } - if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true } - if (method.key) { this$1.unexpected(); } - method.computed = false; - method.key = this$1.startNodeAt(start, startLoc); - method.key.name = k; - this$1.finishNode(method.key, "Identifier"); - return false - }; - - method.kind = "method"; - method.static = tryContextual("static"); - var isGenerator = this.eat(types.star); - var isAsync = false; - if (!isGenerator) { - if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) { - isAsync = true; - isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star); - } else if (tryContextual("get")) { - method.kind = "get"; - } else if (tryContextual("set")) { - method.kind = "set"; - } - } - if (!method.key) { this.parsePropertyName(method); } - var key = method.key; - if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" || - key.type === "Literal" && key.value === "constructor")) { - if (method.kind !== "method") { this.raise(key.start, "Constructor can't have get/set modifier"); } - if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); } - if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); } - method.kind = "constructor"; - } else if (method.static && key.type === "Identifier" && key.name === "prototype") { - this.raise(key.start, "Classes may not have a static property named prototype"); - } - this.parseClassMethod(classBody, method, isGenerator, isAsync); - if (method.kind === "get" && method.value.params.length !== 0) - { this.raiseRecoverable(method.value.start, "getter should have no params"); } - if (method.kind === "set" && method.value.params.length !== 1) - { this.raiseRecoverable(method.value.start, "setter should have exactly one param"); } - if (method.kind === "set" && method.value.params[0].type === "RestElement") - { this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); } - return method - }; - - pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) { - method.value = this.parseMethod(isGenerator, isAsync); - classBody.body.push(this.finishNode(method, "MethodDefinition")); - }; - - pp$1.parseClassId = function(node, isStatement) { - node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null; - }; - - pp$1.parseClassSuper = function(node) { - node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null; - }; - - // Parses module export declaration. - - pp$1.parseExport = function(node, exports) { - var this$1 = this; - - this.next(); - // export * from '...' - if (this.eat(types.star)) { - this.expectContextual("from"); - if (this.type !== types.string) { this.unexpected(); } - node.source = this.parseExprAtom(); - this.semicolon(); - return this.finishNode(node, "ExportAllDeclaration") - } - if (this.eat(types._default)) { // export default ... - this.checkExport(exports, "default", this.lastTokStart); - var isAsync; - if (this.type === types._function || (isAsync = this.isAsyncFunction())) { - var fNode = this.startNode(); - this.next(); - if (isAsync) { this.next(); } - node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync); - } else if (this.type === types._class) { - var cNode = this.startNode(); - node.declaration = this.parseClass(cNode, "nullableID"); - } else { - node.declaration = this.parseMaybeAssign(); - this.semicolon(); - } - return this.finishNode(node, "ExportDefaultDeclaration") - } - // export var|const|let|function|class ... - if (this.shouldParseExportStatement()) { - node.declaration = this.parseStatement(true); - if (node.declaration.type === "VariableDeclaration") - { this.checkVariableExport(exports, node.declaration.declarations); } - else - { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); } - node.specifiers = []; - node.source = null; - } else { // export { x, y as z } [from '...'] - node.declaration = null; - node.specifiers = this.parseExportSpecifiers(exports); - if (this.eatContextual("from")) { - if (this.type !== types.string) { this.unexpected(); } - node.source = this.parseExprAtom(); - } else { - // check for keywords used as local names - for (var i = 0, list = node.specifiers; i < list.length; i += 1) { - var spec = list[i]; - - this$1.checkUnreserved(spec.local); - } - - node.source = null; - } - this.semicolon(); - } - return this.finishNode(node, "ExportNamedDeclaration") - }; - - pp$1.checkExport = function(exports, name, pos) { - if (!exports) { return } - if (has(exports, name)) - { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); } - exports[name] = true; - }; - - pp$1.checkPatternExport = function(exports, pat) { - var this$1 = this; - - var type = pat.type; - if (type === "Identifier") - { this.checkExport(exports, pat.name, pat.start); } - else if (type === "ObjectPattern") - { for (var i = 0, list = pat.properties; i < list.length; i += 1) - { - var prop = list[i]; - - this$1.checkPatternExport(exports, prop); - } } - else if (type === "ArrayPattern") - { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) { - var elt = list$1[i$1]; - - if (elt) { this$1.checkPatternExport(exports, elt); } - } } - else if (type === "Property") - { this.checkPatternExport(exports, pat.value); } - else if (type === "AssignmentPattern") - { this.checkPatternExport(exports, pat.left); } - else if (type === "RestElement") - { this.checkPatternExport(exports, pat.argument); } - else if (type === "ParenthesizedExpression") - { this.checkPatternExport(exports, pat.expression); } - }; - - pp$1.checkVariableExport = function(exports, decls) { - var this$1 = this; - - if (!exports) { return } - for (var i = 0, list = decls; i < list.length; i += 1) - { - var decl = list[i]; - - this$1.checkPatternExport(exports, decl.id); - } - }; - - pp$1.shouldParseExportStatement = function() { - return this.type.keyword === "var" || - this.type.keyword === "const" || - this.type.keyword === "class" || - this.type.keyword === "function" || - this.isLet() || - this.isAsyncFunction() - }; - - // Parses a comma-separated list of module exports. - - pp$1.parseExportSpecifiers = function(exports) { - var this$1 = this; - - var nodes = [], first = true; - // export { x, y as z } [from '...'] - this.expect(types.braceL); - while (!this.eat(types.braceR)) { - if (!first) { - this$1.expect(types.comma); - if (this$1.afterTrailingComma(types.braceR)) { break } - } else { first = false; } - - var node = this$1.startNode(); - node.local = this$1.parseIdent(true); - node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local; - this$1.checkExport(exports, node.exported.name, node.exported.start); - nodes.push(this$1.finishNode(node, "ExportSpecifier")); - } - return nodes - }; - - // Parses import declaration. - - pp$1.parseImport = function(node) { - this.next(); - // import '...' - if (this.type === types.string) { - node.specifiers = empty; - node.source = this.parseExprAtom(); - } else { - node.specifiers = this.parseImportSpecifiers(); - this.expectContextual("from"); - node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected(); - } - this.semicolon(); - return this.finishNode(node, "ImportDeclaration") - }; - - // Parses a comma-separated list of module imports. - - pp$1.parseImportSpecifiers = function() { - var this$1 = this; - - var nodes = [], first = true; - if (this.type === types.name) { - // import defaultObj, { x, y as z } from '...' - var node = this.startNode(); - node.local = this.parseIdent(); - this.checkLVal(node.local, "let"); - nodes.push(this.finishNode(node, "ImportDefaultSpecifier")); - if (!this.eat(types.comma)) { return nodes } - } - if (this.type === types.star) { - var node$1 = this.startNode(); - this.next(); - this.expectContextual("as"); - node$1.local = this.parseIdent(); - this.checkLVal(node$1.local, "let"); - nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier")); - return nodes - } - this.expect(types.braceL); - while (!this.eat(types.braceR)) { - if (!first) { - this$1.expect(types.comma); - if (this$1.afterTrailingComma(types.braceR)) { break } - } else { first = false; } - - var node$2 = this$1.startNode(); - node$2.imported = this$1.parseIdent(true); - if (this$1.eatContextual("as")) { - node$2.local = this$1.parseIdent(); - } else { - this$1.checkUnreserved(node$2.imported); - node$2.local = node$2.imported; - } - this$1.checkLVal(node$2.local, "let"); - nodes.push(this$1.finishNode(node$2, "ImportSpecifier")); - } - return nodes - }; - - // Set `ExpressionStatement#directive` property for directive prologues. - pp$1.adaptDirectivePrologue = function(statements) { - for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) { - statements[i].directive = statements[i].expression.raw.slice(1, -1); - } - }; - pp$1.isDirectiveCandidate = function(statement) { - return ( - statement.type === "ExpressionStatement" && - statement.expression.type === "Literal" && - typeof statement.expression.value === "string" && - // Reject parenthesized strings. - (this.input[statement.start] === "\"" || this.input[statement.start] === "'") - ) - }; - - var pp$2 = Parser.prototype; - - // Convert existing expression atom to assignable pattern - // if possible. - - pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) { - var this$1 = this; - - if (this.options.ecmaVersion >= 6 && node) { - switch (node.type) { - case "Identifier": - if (this.inAsync && node.name === "await") - { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); } - break - - case "ObjectPattern": - case "ArrayPattern": - case "RestElement": - break - - case "ObjectExpression": - node.type = "ObjectPattern"; - if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); } - for (var i = 0, list = node.properties; i < list.length; i += 1) { - var prop = list[i]; - - this$1.toAssignable(prop, isBinding); - // Early error: - // AssignmentRestProperty[Yield, Await] : - // `...` DestructuringAssignmentTarget[Yield, Await] - // - // It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|. - if ( - prop.type === "RestElement" && - (prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern") - ) { - this$1.raise(prop.argument.start, "Unexpected token"); - } - } - break - - case "Property": - // AssignmentProperty has type === "Property" - if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); } - this.toAssignable(node.value, isBinding); - break - - case "ArrayExpression": - node.type = "ArrayPattern"; - if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); } - this.toAssignableList(node.elements, isBinding); - break - - case "SpreadElement": - node.type = "RestElement"; - this.toAssignable(node.argument, isBinding); - if (node.argument.type === "AssignmentPattern") - { this.raise(node.argument.start, "Rest elements cannot have a default value"); } - break - - case "AssignmentExpression": - if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); } - node.type = "AssignmentPattern"; - delete node.operator; - this.toAssignable(node.left, isBinding); - // falls through to AssignmentPattern - - case "AssignmentPattern": - break - - case "ParenthesizedExpression": - this.toAssignable(node.expression, isBinding); - break - - case "MemberExpression": - if (!isBinding) { break } - - default: - this.raise(node.start, "Assigning to rvalue"); - } - } else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); } - return node - }; - - // Convert list of expression atoms to binding list. - - pp$2.toAssignableList = function(exprList, isBinding) { - var this$1 = this; - - var end = exprList.length; - for (var i = 0; i < end; i++) { - var elt = exprList[i]; - if (elt) { this$1.toAssignable(elt, isBinding); } - } - if (end) { - var last = exprList[end - 1]; - if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier") - { this.unexpected(last.argument.start); } - } - return exprList - }; - - // Parses spread element. - - pp$2.parseSpread = function(refDestructuringErrors) { - var node = this.startNode(); - this.next(); - node.argument = this.parseMaybeAssign(false, refDestructuringErrors); - return this.finishNode(node, "SpreadElement") - }; - - pp$2.parseRestBinding = function() { - var node = this.startNode(); - this.next(); - - // RestElement inside of a function parameter must be an identifier - if (this.options.ecmaVersion === 6 && this.type !== types.name) - { this.unexpected(); } - - node.argument = this.parseBindingAtom(); - - return this.finishNode(node, "RestElement") - }; - - // Parses lvalue (assignable) atom. - - pp$2.parseBindingAtom = function() { - if (this.options.ecmaVersion >= 6) { - switch (this.type) { - case types.bracketL: - var node = this.startNode(); - this.next(); - node.elements = this.parseBindingList(types.bracketR, true, true); - return this.finishNode(node, "ArrayPattern") - - case types.braceL: - return this.parseObj(true) - } - } - return this.parseIdent() - }; - - pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) { - var this$1 = this; - - var elts = [], first = true; - while (!this.eat(close)) { - if (first) { first = false; } - else { this$1.expect(types.comma); } - if (allowEmpty && this$1.type === types.comma) { - elts.push(null); - } else if (allowTrailingComma && this$1.afterTrailingComma(close)) { - break - } else if (this$1.type === types.ellipsis) { - var rest = this$1.parseRestBinding(); - this$1.parseBindingListItem(rest); - elts.push(rest); - if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); } - this$1.expect(close); - break - } else { - var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc); - this$1.parseBindingListItem(elem); - elts.push(elem); - } - } - return elts - }; - - pp$2.parseBindingListItem = function(param) { - return param - }; - - // Parses assignment pattern around given atom if possible. - - pp$2.parseMaybeDefault = function(startPos, startLoc, left) { - left = left || this.parseBindingAtom(); - if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left } - var node = this.startNodeAt(startPos, startLoc); - node.left = left; - node.right = this.parseMaybeAssign(); - return this.finishNode(node, "AssignmentPattern") - }; - - // Verify that a node is an lval — something that can be assigned - // to. - // bindingType can be either: - // 'var' indicating that the lval creates a 'var' binding - // 'let' indicating that the lval creates a lexical ('let' or 'const') binding - // 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references - - pp$2.checkLVal = function(expr, bindingType, checkClashes) { - var this$1 = this; - - switch (expr.type) { - case "Identifier": - if (this.strict && this.reservedWordsStrictBind.test(expr.name)) - { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); } - if (checkClashes) { - if (has(checkClashes, expr.name)) - { this.raiseRecoverable(expr.start, "Argument name clash"); } - checkClashes[expr.name] = true; - } - if (bindingType && bindingType !== "none") { - if ( - bindingType === "var" && !this.canDeclareVarName(expr.name) || - bindingType !== "var" && !this.canDeclareLexicalName(expr.name) - ) { - this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared")); - } - if (bindingType === "var") { - this.declareVarName(expr.name); - } else { - this.declareLexicalName(expr.name); - } - } - break - - case "MemberExpression": - if (bindingType) { this.raiseRecoverable(expr.start, "Binding member expression"); } - break - - case "ObjectPattern": - for (var i = 0, list = expr.properties; i < list.length; i += 1) - { - var prop = list[i]; - - this$1.checkLVal(prop, bindingType, checkClashes); - } - break - - case "Property": - // AssignmentProperty has type === "Property" - this.checkLVal(expr.value, bindingType, checkClashes); - break - - case "ArrayPattern": - for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) { - var elem = list$1[i$1]; - - if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); } - } - break - - case "AssignmentPattern": - this.checkLVal(expr.left, bindingType, checkClashes); - break - - case "RestElement": - this.checkLVal(expr.argument, bindingType, checkClashes); - break - - case "ParenthesizedExpression": - this.checkLVal(expr.expression, bindingType, checkClashes); - break - - default: - this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue"); - } - }; - - // A recursive descent parser operates by defining functions for all - // syntactic elements, and recursively calling those, each function - // advancing the input stream and returning an AST node. Precedence - // of constructs (for example, the fact that `!x[1]` means `!(x[1])` - // instead of `(!x)[1]` is handled by the fact that the parser - // function that parses unary prefix operators is called first, and - // in turn calls the function that parses `[]` subscripts — that - // way, it'll receive the node for `x[1]` already parsed, and wraps - // *that* in the unary operator node. - // - // Acorn uses an [operator precedence parser][opp] to handle binary - // operator precedence, because it is much more compact than using - // the technique outlined above, which uses different, nesting - // functions to specify precedence, for all of the ten binary - // precedence levels that JavaScript defines. - // - // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser - - var pp$3 = Parser.prototype; - - // Check if property name clashes with already added. - // Object/class getters and setters are not allowed to clash — - // either with each other or with an init property — and in - // strict mode, init properties are also not allowed to be repeated. - - pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) { - if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement") - { return } - if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand)) - { return } - var key = prop.key; - var name; - switch (key.type) { - case "Identifier": name = key.name; break - case "Literal": name = String(key.value); break - default: return - } - var kind = prop.kind; - if (this.options.ecmaVersion >= 6) { - if (name === "__proto__" && kind === "init") { - if (propHash.proto) { - if (refDestructuringErrors && refDestructuringErrors.doubleProto < 0) { refDestructuringErrors.doubleProto = key.start; } - // Backwards-compat kludge. Can be removed in version 6.0 - else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); } - } - propHash.proto = true; - } - return - } - name = "$" + name; - var other = propHash[name]; - if (other) { - var redefinition; - if (kind === "init") { - redefinition = this.strict && other.init || other.get || other.set; - } else { - redefinition = other.init || other[kind]; - } - if (redefinition) - { this.raiseRecoverable(key.start, "Redefinition of property"); } - } else { - other = propHash[name] = { - init: false, - get: false, - set: false - }; - } - other[kind] = true; - }; - - // ### Expression parsing - - // These nest, from the most general expression type at the top to - // 'atomic', nondivisible expression types at the bottom. Most of - // the functions will simply let the function(s) below them parse, - // and, *if* the syntactic construct they handle is present, wrap - // the AST node that the inner parser gave them in another node. - - // Parse a full expression. The optional arguments are used to - // forbid the `in` operator (in for loops initalization expressions) - // and provide reference for storing '=' operator inside shorthand - // property assignment in contexts where both object expression - // and object pattern might appear (so it's possible to raise - // delayed syntax error at correct position). - - pp$3.parseExpression = function(noIn, refDestructuringErrors) { - var this$1 = this; - - var startPos = this.start, startLoc = this.startLoc; - var expr = this.parseMaybeAssign(noIn, refDestructuringErrors); - if (this.type === types.comma) { - var node = this.startNodeAt(startPos, startLoc); - node.expressions = [expr]; - while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); } - return this.finishNode(node, "SequenceExpression") - } - return expr - }; - - // Parse an assignment expression. This includes applications of - // operators like `+=`. - - pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) { - if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() } - - var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1; - if (refDestructuringErrors) { - oldParenAssign = refDestructuringErrors.parenthesizedAssign; - oldTrailingComma = refDestructuringErrors.trailingComma; - refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1; - } else { - refDestructuringErrors = new DestructuringErrors; - ownDestructuringErrors = true; - } - - var startPos = this.start, startLoc = this.startLoc; - if (this.type === types.parenL || this.type === types.name) - { this.potentialArrowAt = this.start; } - var left = this.parseMaybeConditional(noIn, refDestructuringErrors); - if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); } - if (this.type.isAssign) { - var node = this.startNodeAt(startPos, startLoc); - node.operator = this.value; - node.left = this.type === types.eq ? this.toAssignable(left, false, refDestructuringErrors) : left; - if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); } - refDestructuringErrors.shorthandAssign = -1; // reset because shorthand default was used correctly - this.checkLVal(left); - this.next(); - node.right = this.parseMaybeAssign(noIn); - return this.finishNode(node, "AssignmentExpression") - } else { - if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); } - } - if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; } - if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; } - return left - }; - - // Parse a ternary conditional (`?:`) operator. - - pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) { - var startPos = this.start, startLoc = this.startLoc; - var expr = this.parseExprOps(noIn, refDestructuringErrors); - if (this.checkExpressionErrors(refDestructuringErrors)) { return expr } - if (this.eat(types.question)) { - var node = this.startNodeAt(startPos, startLoc); - node.test = expr; - node.consequent = this.parseMaybeAssign(); - this.expect(types.colon); - node.alternate = this.parseMaybeAssign(noIn); - return this.finishNode(node, "ConditionalExpression") - } - return expr - }; - - // Start the precedence parser. - - pp$3.parseExprOps = function(noIn, refDestructuringErrors) { - var startPos = this.start, startLoc = this.startLoc; - var expr = this.parseMaybeUnary(refDestructuringErrors, false); - if (this.checkExpressionErrors(refDestructuringErrors)) { return expr } - return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn) - }; - - // Parse binary operators with the operator precedence parsing - // algorithm. `left` is the left-hand side of the operator. - // `minPrec` provides context that allows the function to stop and - // defer further parser to one of its callers when it encounters an - // operator that has a lower precedence than the set it is parsing. - - pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) { - var prec = this.type.binop; - if (prec != null && (!noIn || this.type !== types._in)) { - if (prec > minPrec) { - var logical = this.type === types.logicalOR || this.type === types.logicalAND; - var op = this.value; - this.next(); - var startPos = this.start, startLoc = this.startLoc; - var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn); - var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical); - return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn) - } - } - return left - }; - - pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) { - var node = this.startNodeAt(startPos, startLoc); - node.left = left; - node.operator = op; - node.right = right; - return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression") - }; - - // Parse unary operators, both prefix and postfix. - - pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) { - var this$1 = this; - - var startPos = this.start, startLoc = this.startLoc, expr; - if (this.isContextual("await") && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction))) { - expr = this.parseAwait(); - sawUnary = true; - } else if (this.type.prefix) { - var node = this.startNode(), update = this.type === types.incDec; - node.operator = this.value; - node.prefix = true; - this.next(); - node.argument = this.parseMaybeUnary(null, true); - this.checkExpressionErrors(refDestructuringErrors, true); - if (update) { this.checkLVal(node.argument); } - else if (this.strict && node.operator === "delete" && - node.argument.type === "Identifier") - { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); } - else { sawUnary = true; } - expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression"); - } else { - expr = this.parseExprSubscripts(refDestructuringErrors); - if (this.checkExpressionErrors(refDestructuringErrors)) { return expr } - while (this.type.postfix && !this.canInsertSemicolon()) { - var node$1 = this$1.startNodeAt(startPos, startLoc); - node$1.operator = this$1.value; - node$1.prefix = false; - node$1.argument = expr; - this$1.checkLVal(expr); - this$1.next(); - expr = this$1.finishNode(node$1, "UpdateExpression"); - } - } - - if (!sawUnary && this.eat(types.starstar)) - { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) } - else - { return expr } - }; - - // Parse call, dot, and `[]`-subscript expressions. - - pp$3.parseExprSubscripts = function(refDestructuringErrors) { - var startPos = this.start, startLoc = this.startLoc; - var expr = this.parseExprAtom(refDestructuringErrors); - var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")"; - if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr } - var result = this.parseSubscripts(expr, startPos, startLoc); - if (refDestructuringErrors && result.type === "MemberExpression") { - if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; } - if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; } - } - return result - }; - - pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) { - var this$1 = this; - - var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" && - this.lastTokEnd === base.end && !this.canInsertSemicolon() && this.input.slice(base.start, base.end) === "async"; - for (var computed = (void 0);;) { - if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) { - var node = this$1.startNodeAt(startPos, startLoc); - node.object = base; - node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true); - node.computed = !!computed; - if (computed) { this$1.expect(types.bracketR); } - base = this$1.finishNode(node, "MemberExpression"); - } else if (!noCalls && this$1.eat(types.parenL)) { - var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos; - this$1.yieldPos = 0; - this$1.awaitPos = 0; - var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors); - if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) { - this$1.checkPatternErrors(refDestructuringErrors, false); - this$1.checkYieldAwaitInDefaultParams(); - this$1.yieldPos = oldYieldPos; - this$1.awaitPos = oldAwaitPos; - return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true) - } - this$1.checkExpressionErrors(refDestructuringErrors, true); - this$1.yieldPos = oldYieldPos || this$1.yieldPos; - this$1.awaitPos = oldAwaitPos || this$1.awaitPos; - var node$1 = this$1.startNodeAt(startPos, startLoc); - node$1.callee = base; - node$1.arguments = exprList; - base = this$1.finishNode(node$1, "CallExpression"); - } else if (this$1.type === types.backQuote) { - var node$2 = this$1.startNodeAt(startPos, startLoc); - node$2.tag = base; - node$2.quasi = this$1.parseTemplate({isTagged: true}); - base = this$1.finishNode(node$2, "TaggedTemplateExpression"); - } else { - return base - } - } - }; - - // Parse an atomic expression — either a single token that is an - // expression, an expression started by a keyword like `function` or - // `new`, or an expression wrapped in punctuation like `()`, `[]`, - // or `{}`. - - pp$3.parseExprAtom = function(refDestructuringErrors) { - var node, canBeArrow = this.potentialArrowAt === this.start; - switch (this.type) { - case types._super: - if (!this.inFunction) - { this.raise(this.start, "'super' outside of function or class"); } - node = this.startNode(); - this.next(); - // The `super` keyword can appear at below: - // SuperProperty: - // super [ Expression ] - // super . IdentifierName - // SuperCall: - // super Arguments - if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL) - { this.unexpected(); } - return this.finishNode(node, "Super") - - case types._this: - node = this.startNode(); - this.next(); - return this.finishNode(node, "ThisExpression") - - case types.name: - var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc; - var id = this.parseIdent(this.type !== types.name); - if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function)) - { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) } - if (canBeArrow && !this.canInsertSemicolon()) { - if (this.eat(types.arrow)) - { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) } - if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) { - id = this.parseIdent(); - if (this.canInsertSemicolon() || !this.eat(types.arrow)) - { this.unexpected(); } - return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true) - } - } - return id - - case types.regexp: - var value = this.value; - node = this.parseLiteral(value.value); - node.regex = {pattern: value.pattern, flags: value.flags}; - return node - - case types.num: case types.string: - return this.parseLiteral(this.value) - - case types._null: case types._true: case types._false: - node = this.startNode(); - node.value = this.type === types._null ? null : this.type === types._true; - node.raw = this.type.keyword; - this.next(); - return this.finishNode(node, "Literal") - - case types.parenL: - var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow); - if (refDestructuringErrors) { - if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr)) - { refDestructuringErrors.parenthesizedAssign = start; } - if (refDestructuringErrors.parenthesizedBind < 0) - { refDestructuringErrors.parenthesizedBind = start; } - } - return expr - - case types.bracketL: - node = this.startNode(); - this.next(); - node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors); - return this.finishNode(node, "ArrayExpression") - - case types.braceL: - return this.parseObj(false, refDestructuringErrors) - - case types._function: - node = this.startNode(); - this.next(); - return this.parseFunction(node, false) - - case types._class: - return this.parseClass(this.startNode(), false) - - case types._new: - return this.parseNew() - - case types.backQuote: - return this.parseTemplate() - - default: - this.unexpected(); - } - }; - - pp$3.parseLiteral = function(value) { - var node = this.startNode(); - node.value = value; - node.raw = this.input.slice(this.start, this.end); - this.next(); - return this.finishNode(node, "Literal") - }; - - pp$3.parseParenExpression = function() { - this.expect(types.parenL); - var val = this.parseExpression(); - this.expect(types.parenR); - return val - }; - - pp$3.parseParenAndDistinguishExpression = function(canBeArrow) { - var this$1 = this; - - var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8; - if (this.options.ecmaVersion >= 6) { - this.next(); - - var innerStartPos = this.start, innerStartLoc = this.startLoc; - var exprList = [], first = true, lastIsComma = false; - var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart; - this.yieldPos = 0; - this.awaitPos = 0; - while (this.type !== types.parenR) { - first ? first = false : this$1.expect(types.comma); - if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) { - lastIsComma = true; - break - } else if (this$1.type === types.ellipsis) { - spreadStart = this$1.start; - exprList.push(this$1.parseParenItem(this$1.parseRestBinding())); - if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); } - break - } else { - exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem)); - } - } - var innerEndPos = this.start, innerEndLoc = this.startLoc; - this.expect(types.parenR); - - if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) { - this.checkPatternErrors(refDestructuringErrors, false); - this.checkYieldAwaitInDefaultParams(); - this.yieldPos = oldYieldPos; - this.awaitPos = oldAwaitPos; - return this.parseParenArrowList(startPos, startLoc, exprList) - } - - if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); } - if (spreadStart) { this.unexpected(spreadStart); } - this.checkExpressionErrors(refDestructuringErrors, true); - this.yieldPos = oldYieldPos || this.yieldPos; - this.awaitPos = oldAwaitPos || this.awaitPos; - - if (exprList.length > 1) { - val = this.startNodeAt(innerStartPos, innerStartLoc); - val.expressions = exprList; - this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc); - } else { - val = exprList[0]; - } - } else { - val = this.parseParenExpression(); - } - - if (this.options.preserveParens) { - var par = this.startNodeAt(startPos, startLoc); - par.expression = val; - return this.finishNode(par, "ParenthesizedExpression") - } else { - return val - } - }; - - pp$3.parseParenItem = function(item) { - return item - }; - - pp$3.parseParenArrowList = function(startPos, startLoc, exprList) { - return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList) - }; - - // New's precedence is slightly tricky. It must allow its argument to - // be a `[]` or dot subscript expression, but not a call — at least, - // not without wrapping it in parentheses. Thus, it uses the noCalls - // argument to parseSubscripts to prevent it from consuming the - // argument list. - - var empty$1 = []; - - pp$3.parseNew = function() { - var node = this.startNode(); - var meta = this.parseIdent(true); - if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) { - node.meta = meta; - var containsEsc = this.containsEsc; - node.property = this.parseIdent(true); - if (node.property.name !== "target" || containsEsc) - { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); } - if (!this.inFunction) - { this.raiseRecoverable(node.start, "new.target can only be used in functions"); } - return this.finishNode(node, "MetaProperty") - } - var startPos = this.start, startLoc = this.startLoc; - node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true); - if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); } - else { node.arguments = empty$1; } - return this.finishNode(node, "NewExpression") - }; - - // Parse template expression. - - pp$3.parseTemplateElement = function(ref) { - var isTagged = ref.isTagged; - - var elem = this.startNode(); - if (this.type === types.invalidTemplate) { - if (!isTagged) { - this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal"); - } - elem.value = { - raw: this.value, - cooked: null - }; - } else { - elem.value = { - raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"), - cooked: this.value - }; - } - this.next(); - elem.tail = this.type === types.backQuote; - return this.finishNode(elem, "TemplateElement") - }; - - pp$3.parseTemplate = function(ref) { - var this$1 = this; - if ( ref === void 0 ) ref = {}; - var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false; - - var node = this.startNode(); - this.next(); - node.expressions = []; - var curElt = this.parseTemplateElement({isTagged: isTagged}); - node.quasis = [curElt]; - while (!curElt.tail) { - this$1.expect(types.dollarBraceL); - node.expressions.push(this$1.parseExpression()); - this$1.expect(types.braceR); - node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged})); - } - this.next(); - return this.finishNode(node, "TemplateLiteral") - }; - - pp$3.isAsyncProp = function(prop) { - return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" && - (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword || (this.options.ecmaVersion >= 9 && this.type === types.star)) && - !lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) - }; - - // Parse an object literal or binding pattern. - - pp$3.parseObj = function(isPattern, refDestructuringErrors) { - var this$1 = this; - - var node = this.startNode(), first = true, propHash = {}; - node.properties = []; - this.next(); - while (!this.eat(types.braceR)) { - if (!first) { - this$1.expect(types.comma); - if (this$1.afterTrailingComma(types.braceR)) { break } - } else { first = false; } - - var prop = this$1.parseProperty(isPattern, refDestructuringErrors); - if (!isPattern) { this$1.checkPropClash(prop, propHash, refDestructuringErrors); } - node.properties.push(prop); - } - return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression") - }; - - pp$3.parseProperty = function(isPattern, refDestructuringErrors) { - var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc; - if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) { - if (isPattern) { - prop.argument = this.parseIdent(false); - if (this.type === types.comma) { - this.raise(this.start, "Comma is not permitted after the rest element"); - } - return this.finishNode(prop, "RestElement") - } - // To disallow parenthesized identifier via `this.toAssignable()`. - if (this.type === types.parenL && refDestructuringErrors) { - if (refDestructuringErrors.parenthesizedAssign < 0) { - refDestructuringErrors.parenthesizedAssign = this.start; - } - if (refDestructuringErrors.parenthesizedBind < 0) { - refDestructuringErrors.parenthesizedBind = this.start; - } - } - // Parse argument. - prop.argument = this.parseMaybeAssign(false, refDestructuringErrors); - // To disallow trailing comma via `this.toAssignable()`. - if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) { - refDestructuringErrors.trailingComma = this.start; - } - // Finish - return this.finishNode(prop, "SpreadElement") - } - if (this.options.ecmaVersion >= 6) { - prop.method = false; - prop.shorthand = false; - if (isPattern || refDestructuringErrors) { - startPos = this.start; - startLoc = this.startLoc; - } - if (!isPattern) - { isGenerator = this.eat(types.star); } - } - var containsEsc = this.containsEsc; - this.parsePropertyName(prop); - if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) { - isAsync = true; - isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star); - this.parsePropertyName(prop, refDestructuringErrors); - } else { - isAsync = false; - } - this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc); - return this.finishNode(prop, "Property") - }; - - pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) { - if ((isGenerator || isAsync) && this.type === types.colon) - { this.unexpected(); } - - if (this.eat(types.colon)) { - prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors); - prop.kind = "init"; - } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) { - if (isPattern) { this.unexpected(); } - prop.kind = "init"; - prop.method = true; - prop.value = this.parseMethod(isGenerator, isAsync); - } else if (!isPattern && !containsEsc && - this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" && - (prop.key.name === "get" || prop.key.name === "set") && - (this.type !== types.comma && this.type !== types.braceR)) { - if (isGenerator || isAsync) { this.unexpected(); } - prop.kind = prop.key.name; - this.parsePropertyName(prop); - prop.value = this.parseMethod(false); - var paramCount = prop.kind === "get" ? 0 : 1; - if (prop.value.params.length !== paramCount) { - var start = prop.value.start; - if (prop.kind === "get") - { this.raiseRecoverable(start, "getter should have no params"); } - else - { this.raiseRecoverable(start, "setter should have exactly one param"); } - } else { - if (prop.kind === "set" && prop.value.params[0].type === "RestElement") - { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); } - } - } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") { - this.checkUnreserved(prop.key); - prop.kind = "init"; - if (isPattern) { - prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key); - } else if (this.type === types.eq && refDestructuringErrors) { - if (refDestructuringErrors.shorthandAssign < 0) - { refDestructuringErrors.shorthandAssign = this.start; } - prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key); - } else { - prop.value = prop.key; - } - prop.shorthand = true; - } else { this.unexpected(); } - }; - - pp$3.parsePropertyName = function(prop) { - if (this.options.ecmaVersion >= 6) { - if (this.eat(types.bracketL)) { - prop.computed = true; - prop.key = this.parseMaybeAssign(); - this.expect(types.bracketR); - return prop.key - } else { - prop.computed = false; - } - } - return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true) - }; - - // Initialize empty function node. - - pp$3.initFunction = function(node) { - node.id = null; - if (this.options.ecmaVersion >= 6) { - node.generator = false; - node.expression = false; - } - if (this.options.ecmaVersion >= 8) - { node.async = false; } - }; - - // Parse object or class method. - - pp$3.parseMethod = function(isGenerator, isAsync) { - var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync, - oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction; - - this.initFunction(node); - if (this.options.ecmaVersion >= 6) - { node.generator = isGenerator; } - if (this.options.ecmaVersion >= 8) - { node.async = !!isAsync; } - - this.inGenerator = node.generator; - this.inAsync = node.async; - this.yieldPos = 0; - this.awaitPos = 0; - this.inFunction = true; - this.enterFunctionScope(); - - this.expect(types.parenL); - node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8); - this.checkYieldAwaitInDefaultParams(); - this.parseFunctionBody(node, false); - - this.inGenerator = oldInGen; - this.inAsync = oldInAsync; - this.yieldPos = oldYieldPos; - this.awaitPos = oldAwaitPos; - this.inFunction = oldInFunc; - return this.finishNode(node, "FunctionExpression") - }; - - // Parse arrow function expression with given parameters. - - pp$3.parseArrowExpression = function(node, params, isAsync) { - var oldInGen = this.inGenerator, oldInAsync = this.inAsync, - oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction; - - this.enterFunctionScope(); - this.initFunction(node); - if (this.options.ecmaVersion >= 8) - { node.async = !!isAsync; } - - this.inGenerator = false; - this.inAsync = node.async; - this.yieldPos = 0; - this.awaitPos = 0; - this.inFunction = true; - - node.params = this.toAssignableList(params, true); - this.parseFunctionBody(node, true); - - this.inGenerator = oldInGen; - this.inAsync = oldInAsync; - this.yieldPos = oldYieldPos; - this.awaitPos = oldAwaitPos; - this.inFunction = oldInFunc; - return this.finishNode(node, "ArrowFunctionExpression") - }; - - // Parse function body and check parameters. - - pp$3.parseFunctionBody = function(node, isArrowFunction) { - var isExpression = isArrowFunction && this.type !== types.braceL; - var oldStrict = this.strict, useStrict = false; - - if (isExpression) { - node.body = this.parseMaybeAssign(); - node.expression = true; - this.checkParams(node, false); - } else { - var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params); - if (!oldStrict || nonSimple) { - useStrict = this.strictDirective(this.end); - // If this is a strict mode function, verify that argument names - // are not repeated, and it does not try to bind the words `eval` - // or `arguments`. - if (useStrict && nonSimple) - { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); } - } - // Start a new scope with regard to labels and the `inFunction` - // flag (restore them to their old value afterwards). - var oldLabels = this.labels; - this.labels = []; - if (useStrict) { this.strict = true; } - - // Add the params to varDeclaredNames to ensure that an error is thrown - // if a let/const declaration in the function clashes with one of the params. - this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params)); - node.body = this.parseBlock(false); - node.expression = false; - this.adaptDirectivePrologue(node.body.body); - this.labels = oldLabels; - } - this.exitFunctionScope(); - - if (this.strict && node.id) { - // Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval' - this.checkLVal(node.id, "none"); - } - this.strict = oldStrict; - }; - - pp$3.isSimpleParamList = function(params) { - for (var i = 0, list = params; i < list.length; i += 1) - { - var param = list[i]; - - if (param.type !== "Identifier") { return false - } } - return true - }; - - // Checks function params for various disallowed patterns such as using "eval" - // or "arguments" and duplicate parameters. - - pp$3.checkParams = function(node, allowDuplicates) { - var this$1 = this; - - var nameHash = {}; - for (var i = 0, list = node.params; i < list.length; i += 1) - { - var param = list[i]; - - this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash); - } - }; - - // Parses a comma-separated list of expressions, and returns them as - // an array. `close` is the token type that ends the list, and - // `allowEmpty` can be turned on to allow subsequent commas with - // nothing in between them to be parsed as `null` (which is needed - // for array literals). - - pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) { - var this$1 = this; - - var elts = [], first = true; - while (!this.eat(close)) { - if (!first) { - this$1.expect(types.comma); - if (allowTrailingComma && this$1.afterTrailingComma(close)) { break } - } else { first = false; } - - var elt = (void 0); - if (allowEmpty && this$1.type === types.comma) - { elt = null; } - else if (this$1.type === types.ellipsis) { - elt = this$1.parseSpread(refDestructuringErrors); - if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0) - { refDestructuringErrors.trailingComma = this$1.start; } - } else { - elt = this$1.parseMaybeAssign(false, refDestructuringErrors); - } - elts.push(elt); - } - return elts - }; - - pp$3.checkUnreserved = function(ref) { - var start = ref.start; - var end = ref.end; - var name = ref.name; - - if (this.inGenerator && name === "yield") - { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); } - if (this.inAsync && name === "await") - { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); } - if (this.isKeyword(name)) - { this.raise(start, ("Unexpected keyword '" + name + "'")); } - if (this.options.ecmaVersion < 6 && - this.input.slice(start, end).indexOf("\\") !== -1) { return } - var re = this.strict ? this.reservedWordsStrict : this.reservedWords; - if (re.test(name)) { - if (!this.inAsync && name === "await") - { this.raiseRecoverable(start, "Can not use keyword 'await' outside an async function"); } - this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved")); - } - }; - - // Parse the next token as an identifier. If `liberal` is true (used - // when parsing properties), it will also convert keywords into - // identifiers. - - pp$3.parseIdent = function(liberal, isBinding) { - var node = this.startNode(); - if (liberal && this.options.allowReserved === "never") { liberal = false; } - if (this.type === types.name) { - node.name = this.value; - } else if (this.type.keyword) { - node.name = this.type.keyword; - - // To fix https://github.com/acornjs/acorn/issues/575 - // `class` and `function` keywords push new context into this.context. - // But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name. - // If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword - if ((node.name === "class" || node.name === "function") && - (this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) { - this.context.pop(); - } - } else { - this.unexpected(); - } - this.next(); - this.finishNode(node, "Identifier"); - if (!liberal) { this.checkUnreserved(node); } - return node - }; - - // Parses yield expression inside generator. - - pp$3.parseYield = function() { - if (!this.yieldPos) { this.yieldPos = this.start; } - - var node = this.startNode(); - this.next(); - if (this.type === types.semi || this.canInsertSemicolon() || (this.type !== types.star && !this.type.startsExpr)) { - node.delegate = false; - node.argument = null; - } else { - node.delegate = this.eat(types.star); - node.argument = this.parseMaybeAssign(); - } - return this.finishNode(node, "YieldExpression") - }; - - pp$3.parseAwait = function() { - if (!this.awaitPos) { this.awaitPos = this.start; } - - var node = this.startNode(); - this.next(); - node.argument = this.parseMaybeUnary(null, true); - return this.finishNode(node, "AwaitExpression") - }; - - var pp$4 = Parser.prototype; - - // This function is used to raise exceptions on parse errors. It - // takes an offset integer (into the current `input`) to indicate - // the location of the error, attaches the position to the end - // of the error message, and then raises a `SyntaxError` with that - // message. - - pp$4.raise = function(pos, message) { - var loc = getLineInfo(this.input, pos); - message += " (" + loc.line + ":" + loc.column + ")"; - var err = new SyntaxError(message); - err.pos = pos; err.loc = loc; err.raisedAt = this.pos; - throw err - }; - - pp$4.raiseRecoverable = pp$4.raise; - - pp$4.curPosition = function() { - if (this.options.locations) { - return new Position(this.curLine, this.pos - this.lineStart) - } - }; - - var pp$5 = Parser.prototype; - - // Object.assign polyfill - var assign = Object.assign || function(target) { - var sources = [], len = arguments.length - 1; - while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ]; - - for (var i = 0, list = sources; i < list.length; i += 1) { - var source = list[i]; - - for (var key in source) { - if (has(source, key)) { - target[key] = source[key]; - } - } - } - return target - }; - - // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names. - - pp$5.enterFunctionScope = function() { - // var: a hash of var-declared names in the current lexical scope - // lexical: a hash of lexically-declared names in the current lexical scope - // childVar: a hash of var-declared names in all child lexical scopes of the current lexical scope (within the current function scope) - // parentLexical: a hash of lexically-declared names in all parent lexical scopes of the current lexical scope (within the current function scope) - this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}}); - }; - - pp$5.exitFunctionScope = function() { - this.scopeStack.pop(); - }; - - pp$5.enterLexicalScope = function() { - var parentScope = this.scopeStack[this.scopeStack.length - 1]; - var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}}; - - this.scopeStack.push(childScope); - assign(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical); - }; - - pp$5.exitLexicalScope = function() { - var childScope = this.scopeStack.pop(); - var parentScope = this.scopeStack[this.scopeStack.length - 1]; - - assign(parentScope.childVar, childScope.var, childScope.childVar); - }; - - /** - * A name can be declared with `var` if there are no variables with the same name declared with `let`/`const` - * in the current lexical scope or any of the parent lexical scopes in this function. - */ - pp$5.canDeclareVarName = function(name) { - var currentScope = this.scopeStack[this.scopeStack.length - 1]; - - return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name) - }; - - /** - * A name can be declared with `let`/`const` if there are no variables with the same name declared with `let`/`const` - * in the current scope, and there are no variables with the same name declared with `var` in the current scope or in - * any child lexical scopes in this function. - */ - pp$5.canDeclareLexicalName = function(name) { - var currentScope = this.scopeStack[this.scopeStack.length - 1]; - - return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name) - }; - - pp$5.declareVarName = function(name) { - this.scopeStack[this.scopeStack.length - 1].var[name] = true; - }; - - pp$5.declareLexicalName = function(name) { - this.scopeStack[this.scopeStack.length - 1].lexical[name] = true; - }; - - var Node = function Node(parser, pos, loc) { - this.type = ""; - this.start = pos; - this.end = 0; - if (parser.options.locations) - { this.loc = new SourceLocation(parser, loc); } - if (parser.options.directSourceFile) - { this.sourceFile = parser.options.directSourceFile; } - if (parser.options.ranges) - { this.range = [pos, 0]; } - }; - - // Start an AST node, attaching a start offset. - - var pp$6 = Parser.prototype; - - pp$6.startNode = function() { - return new Node(this, this.start, this.startLoc) - }; - - pp$6.startNodeAt = function(pos, loc) { - return new Node(this, pos, loc) - }; - - // Finish an AST node, adding `type` and `end` properties. - - function finishNodeAt(node, type, pos, loc) { - node.type = type; - node.end = pos; - if (this.options.locations) - { node.loc.end = loc; } - if (this.options.ranges) - { node.range[1] = pos; } - return node - } - - pp$6.finishNode = function(node, type) { - return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc) - }; - - // Finish node at given position - - pp$6.finishNodeAt = function(node, type, pos, loc) { - return finishNodeAt.call(this, node, type, pos, loc) - }; - - // The algorithm used to determine whether a regexp can appear at a - // given point in the program is loosely based on sweet.js' approach. - // See https://github.com/mozilla/sweet.js/wiki/design - - var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) { - this.token = token; - this.isExpr = !!isExpr; - this.preserveSpace = !!preserveSpace; - this.override = override; - this.generator = !!generator; - }; - - var types$1 = { - b_stat: new TokContext("{", false), - b_expr: new TokContext("{", true), - b_tmpl: new TokContext("${", false), - p_stat: new TokContext("(", false), - p_expr: new TokContext("(", true), - q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }), - f_stat: new TokContext("function", false), - f_expr: new TokContext("function", true), - f_expr_gen: new TokContext("function", true, false, null, true), - f_gen: new TokContext("function", false, false, null, true) - }; - - var pp$7 = Parser.prototype; - - pp$7.initialContext = function() { - return [types$1.b_stat] - }; - - pp$7.braceIsBlock = function(prevType) { - var parent = this.curContext(); - if (parent === types$1.f_expr || parent === types$1.f_stat) - { return true } - if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr)) - { return !parent.isExpr } - - // The check for `tt.name && exprAllowed` detects whether we are - // after a `yield` or `of` construct. See the `updateContext` for - // `tt.name`. - if (prevType === types._return || prevType === types.name && this.exprAllowed) - { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) } - if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow) - { return true } - if (prevType === types.braceL) - { return parent === types$1.b_stat } - if (prevType === types._var || prevType === types.name) - { return false } - return !this.exprAllowed - }; - - pp$7.inGeneratorContext = function() { - var this$1 = this; - - for (var i = this.context.length - 1; i >= 1; i--) { - var context = this$1.context[i]; - if (context.token === "function") - { return context.generator } - } - return false - }; - - pp$7.updateContext = function(prevType) { - var update, type = this.type; - if (type.keyword && prevType === types.dot) - { this.exprAllowed = false; } - else if (update = type.updateContext) - { update.call(this, prevType); } - else - { this.exprAllowed = type.beforeExpr; } - }; - - // Token-specific context update code - - types.parenR.updateContext = types.braceR.updateContext = function() { - if (this.context.length === 1) { - this.exprAllowed = true; - return - } - var out = this.context.pop(); - if (out === types$1.b_stat && this.curContext().token === "function") { - out = this.context.pop(); - } - this.exprAllowed = !out.isExpr; - }; - - types.braceL.updateContext = function(prevType) { - this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr); - this.exprAllowed = true; - }; - - types.dollarBraceL.updateContext = function() { - this.context.push(types$1.b_tmpl); - this.exprAllowed = true; - }; - - types.parenL.updateContext = function(prevType) { - var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while; - this.context.push(statementParens ? types$1.p_stat : types$1.p_expr); - this.exprAllowed = true; - }; - - types.incDec.updateContext = function() { - // tokExprAllowed stays unchanged - }; - - types._function.updateContext = types._class.updateContext = function(prevType) { - if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else && - !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat)) - { this.context.push(types$1.f_expr); } - else - { this.context.push(types$1.f_stat); } - this.exprAllowed = false; - }; - - types.backQuote.updateContext = function() { - if (this.curContext() === types$1.q_tmpl) - { this.context.pop(); } - else - { this.context.push(types$1.q_tmpl); } - this.exprAllowed = false; - }; - - types.star.updateContext = function(prevType) { - if (prevType === types._function) { - var index = this.context.length - 1; - if (this.context[index] === types$1.f_expr) - { this.context[index] = types$1.f_expr_gen; } - else - { this.context[index] = types$1.f_gen; } - } - this.exprAllowed = true; - }; - - types.name.updateContext = function(prevType) { - var allowed = false; - if (this.options.ecmaVersion >= 6) { - if (this.value === "of" && !this.exprAllowed || - this.value === "yield" && this.inGeneratorContext()) - { allowed = true; } - } - this.exprAllowed = allowed; - }; - - var data = { - "$LONE": [ - "ASCII", - "ASCII_Hex_Digit", - "AHex", - "Alphabetic", - "Alpha", - "Any", - "Assigned", - "Bidi_Control", - "Bidi_C", - "Bidi_Mirrored", - "Bidi_M", - "Case_Ignorable", - "CI", - "Cased", - "Changes_When_Casefolded", - "CWCF", - "Changes_When_Casemapped", - "CWCM", - "Changes_When_Lowercased", - "CWL", - "Changes_When_NFKC_Casefolded", - "CWKCF", - "Changes_When_Titlecased", - "CWT", - "Changes_When_Uppercased", - "CWU", - "Dash", - "Default_Ignorable_Code_Point", - "DI", - "Deprecated", - "Dep", - "Diacritic", - "Dia", - "Emoji", - "Emoji_Component", - "Emoji_Modifier", - "Emoji_Modifier_Base", - "Emoji_Presentation", - "Extender", - "Ext", - "Grapheme_Base", - "Gr_Base", - "Grapheme_Extend", - "Gr_Ext", - "Hex_Digit", - "Hex", - "IDS_Binary_Operator", - "IDSB", - "IDS_Trinary_Operator", - "IDST", - "ID_Continue", - "IDC", - "ID_Start", - "IDS", - "Ideographic", - "Ideo", - "Join_Control", - "Join_C", - "Logical_Order_Exception", - "LOE", - "Lowercase", - "Lower", - "Math", - "Noncharacter_Code_Point", - "NChar", - "Pattern_Syntax", - "Pat_Syn", - "Pattern_White_Space", - "Pat_WS", - "Quotation_Mark", - "QMark", - "Radical", - "Regional_Indicator", - "RI", - "Sentence_Terminal", - "STerm", - "Soft_Dotted", - "SD", - "Terminal_Punctuation", - "Term", - "Unified_Ideograph", - "UIdeo", - "Uppercase", - "Upper", - "Variation_Selector", - "VS", - "White_Space", - "space", - "XID_Continue", - "XIDC", - "XID_Start", - "XIDS" - ], - "General_Category": [ - "Cased_Letter", - "LC", - "Close_Punctuation", - "Pe", - "Connector_Punctuation", - "Pc", - "Control", - "Cc", - "cntrl", - "Currency_Symbol", - "Sc", - "Dash_Punctuation", - "Pd", - "Decimal_Number", - "Nd", - "digit", - "Enclosing_Mark", - "Me", - "Final_Punctuation", - "Pf", - "Format", - "Cf", - "Initial_Punctuation", - "Pi", - "Letter", - "L", - "Letter_Number", - "Nl", - "Line_Separator", - "Zl", - "Lowercase_Letter", - "Ll", - "Mark", - "M", - "Combining_Mark", - "Math_Symbol", - "Sm", - "Modifier_Letter", - "Lm", - "Modifier_Symbol", - "Sk", - "Nonspacing_Mark", - "Mn", - "Number", - "N", - "Open_Punctuation", - "Ps", - "Other", - "C", - "Other_Letter", - "Lo", - "Other_Number", - "No", - "Other_Punctuation", - "Po", - "Other_Symbol", - "So", - "Paragraph_Separator", - "Zp", - "Private_Use", - "Co", - "Punctuation", - "P", - "punct", - "Separator", - "Z", - "Space_Separator", - "Zs", - "Spacing_Mark", - "Mc", - "Surrogate", - "Cs", - "Symbol", - "S", - "Titlecase_Letter", - "Lt", - "Unassigned", - "Cn", - "Uppercase_Letter", - "Lu" - ], - "Script": [ - "Adlam", - "Adlm", - "Ahom", - "Anatolian_Hieroglyphs", - "Hluw", - "Arabic", - "Arab", - "Armenian", - "Armn", - "Avestan", - "Avst", - "Balinese", - "Bali", - "Bamum", - "Bamu", - "Bassa_Vah", - "Bass", - "Batak", - "Batk", - "Bengali", - "Beng", - "Bhaiksuki", - "Bhks", - "Bopomofo", - "Bopo", - "Brahmi", - "Brah", - "Braille", - "Brai", - "Buginese", - "Bugi", - "Buhid", - "Buhd", - "Canadian_Aboriginal", - "Cans", - "Carian", - "Cari", - "Caucasian_Albanian", - "Aghb", - "Chakma", - "Cakm", - "Cham", - "Cherokee", - "Cher", - "Common", - "Zyyy", - "Coptic", - "Copt", - "Qaac", - "Cuneiform", - "Xsux", - "Cypriot", - "Cprt", - "Cyrillic", - "Cyrl", - "Deseret", - "Dsrt", - "Devanagari", - "Deva", - "Duployan", - "Dupl", - "Egyptian_Hieroglyphs", - "Egyp", - "Elbasan", - "Elba", - "Ethiopic", - "Ethi", - "Georgian", - "Geor", - "Glagolitic", - "Glag", - "Gothic", - "Goth", - "Grantha", - "Gran", - "Greek", - "Grek", - "Gujarati", - "Gujr", - "Gurmukhi", - "Guru", - "Han", - "Hani", - "Hangul", - "Hang", - "Hanunoo", - "Hano", - "Hatran", - "Hatr", - "Hebrew", - "Hebr", - "Hiragana", - "Hira", - "Imperial_Aramaic", - "Armi", - "Inherited", - "Zinh", - "Qaai", - "Inscriptional_Pahlavi", - "Phli", - "Inscriptional_Parthian", - "Prti", - "Javanese", - "Java", - "Kaithi", - "Kthi", - "Kannada", - "Knda", - "Katakana", - "Kana", - "Kayah_Li", - "Kali", - "Kharoshthi", - "Khar", - "Khmer", - "Khmr", - "Khojki", - "Khoj", - "Khudawadi", - "Sind", - "Lao", - "Laoo", - "Latin", - "Latn", - "Lepcha", - "Lepc", - "Limbu", - "Limb", - "Linear_A", - "Lina", - "Linear_B", - "Linb", - "Lisu", - "Lycian", - "Lyci", - "Lydian", - "Lydi", - "Mahajani", - "Mahj", - "Malayalam", - "Mlym", - "Mandaic", - "Mand", - "Manichaean", - "Mani", - "Marchen", - "Marc", - "Masaram_Gondi", - "Gonm", - "Meetei_Mayek", - "Mtei", - "Mende_Kikakui", - "Mend", - "Meroitic_Cursive", - "Merc", - "Meroitic_Hieroglyphs", - "Mero", - "Miao", - "Plrd", - "Modi", - "Mongolian", - "Mong", - "Mro", - "Mroo", - "Multani", - "Mult", - "Myanmar", - "Mymr", - "Nabataean", - "Nbat", - "New_Tai_Lue", - "Talu", - "Newa", - "Nko", - "Nkoo", - "Nushu", - "Nshu", - "Ogham", - "Ogam", - "Ol_Chiki", - "Olck", - "Old_Hungarian", - "Hung", - "Old_Italic", - "Ital", - "Old_North_Arabian", - "Narb", - "Old_Permic", - "Perm", - "Old_Persian", - "Xpeo", - "Old_South_Arabian", - "Sarb", - "Old_Turkic", - "Orkh", - "Oriya", - "Orya", - "Osage", - "Osge", - "Osmanya", - "Osma", - "Pahawh_Hmong", - "Hmng", - "Palmyrene", - "Palm", - "Pau_Cin_Hau", - "Pauc", - "Phags_Pa", - "Phag", - "Phoenician", - "Phnx", - "Psalter_Pahlavi", - "Phlp", - "Rejang", - "Rjng", - "Runic", - "Runr", - "Samaritan", - "Samr", - "Saurashtra", - "Saur", - "Sharada", - "Shrd", - "Shavian", - "Shaw", - "Siddham", - "Sidd", - "SignWriting", - "Sgnw", - "Sinhala", - "Sinh", - "Sora_Sompeng", - "Sora", - "Soyombo", - "Soyo", - "Sundanese", - "Sund", - "Syloti_Nagri", - "Sylo", - "Syriac", - "Syrc", - "Tagalog", - "Tglg", - "Tagbanwa", - "Tagb", - "Tai_Le", - "Tale", - "Tai_Tham", - "Lana", - "Tai_Viet", - "Tavt", - "Takri", - "Takr", - "Tamil", - "Taml", - "Tangut", - "Tang", - "Telugu", - "Telu", - "Thaana", - "Thaa", - "Thai", - "Tibetan", - "Tibt", - "Tifinagh", - "Tfng", - "Tirhuta", - "Tirh", - "Ugaritic", - "Ugar", - "Vai", - "Vaii", - "Warang_Citi", - "Wara", - "Yi", - "Yiii", - "Zanabazar_Square", - "Zanb" - ] - }; - Array.prototype.push.apply(data.$LONE, data.General_Category); - data.gc = data.General_Category; - data.sc = data.Script_Extensions = data.scx = data.Script; - - var pp$9 = Parser.prototype; - - var RegExpValidationState = function RegExpValidationState(parser) { - this.parser = parser; - this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : ""); - this.source = ""; - this.flags = ""; - this.start = 0; - this.switchU = false; - this.switchN = false; - this.pos = 0; - this.lastIntValue = 0; - this.lastStringValue = ""; - this.lastAssertionIsQuantifiable = false; - this.numCapturingParens = 0; - this.maxBackReference = 0; - this.groupNames = []; - this.backReferenceNames = []; - }; - - RegExpValidationState.prototype.reset = function reset (start, pattern, flags) { - var unicode = flags.indexOf("u") !== -1; - this.start = start | 0; - this.source = pattern + ""; - this.flags = flags; - this.switchU = unicode && this.parser.options.ecmaVersion >= 6; - this.switchN = unicode && this.parser.options.ecmaVersion >= 9; - }; - - RegExpValidationState.prototype.raise = function raise (message) { - this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message)); - }; - - // If u flag is given, this returns the code point at the index (it combines a surrogate pair). - // Otherwise, this returns the code unit of the index (can be a part of a surrogate pair). - RegExpValidationState.prototype.at = function at (i) { - var s = this.source; - var l = s.length; - if (i >= l) { - return -1 - } - var c = s.charCodeAt(i); - if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) { - return c - } - return (c << 10) + s.charCodeAt(i + 1) - 0x35FDC00 - }; - - RegExpValidationState.prototype.nextIndex = function nextIndex (i) { - var s = this.source; - var l = s.length; - if (i >= l) { - return l - } - var c = s.charCodeAt(i); - if (!this.switchU || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) { - return i + 1 - } - return i + 2 - }; - - RegExpValidationState.prototype.current = function current () { - return this.at(this.pos) - }; - - RegExpValidationState.prototype.lookahead = function lookahead () { - return this.at(this.nextIndex(this.pos)) - }; - - RegExpValidationState.prototype.advance = function advance () { - this.pos = this.nextIndex(this.pos); - }; - - RegExpValidationState.prototype.eat = function eat (ch) { - if (this.current() === ch) { - this.advance(); - return true - } - return false - }; - - function codePointToString$1(ch) { - if (ch <= 0xFFFF) { return String.fromCharCode(ch) } - ch -= 0x10000; - return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00) - } - - /** - * Validate the flags part of a given RegExpLiteral. - * - * @param {RegExpValidationState} state The state to validate RegExp. - * @returns {void} - */ - pp$9.validateRegExpFlags = function(state) { - var this$1 = this; - - var validFlags = state.validFlags; - var flags = state.flags; - - for (var i = 0; i < flags.length; i++) { - var flag = flags.charAt(i); - if (validFlags.indexOf(flag) === -1) { - this$1.raise(state.start, "Invalid regular expression flag"); - } - if (flags.indexOf(flag, i + 1) > -1) { - this$1.raise(state.start, "Duplicate regular expression flag"); - } - } - }; - - /** - * Validate the pattern part of a given RegExpLiteral. - * - * @param {RegExpValidationState} state The state to validate RegExp. - * @returns {void} - */ - pp$9.validateRegExpPattern = function(state) { - this.regexp_pattern(state); - - // The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of - // parsing contains a |GroupName|, reparse with the goal symbol - // |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError* - // exception if _P_ did not conform to the grammar, if any elements of _P_ - // were not matched by the parse, or if any Early Error conditions exist. - if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) { - state.switchN = true; - this.regexp_pattern(state); - } - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern - pp$9.regexp_pattern = function(state) { - state.pos = 0; - state.lastIntValue = 0; - state.lastStringValue = ""; - state.lastAssertionIsQuantifiable = false; - state.numCapturingParens = 0; - state.maxBackReference = 0; - state.groupNames.length = 0; - state.backReferenceNames.length = 0; - - this.regexp_disjunction(state); - - if (state.pos !== state.source.length) { - // Make the same messages as V8. - if (state.eat(0x29 /* ) */)) { - state.raise("Unmatched ')'"); - } - if (state.eat(0x5D /* [ */) || state.eat(0x7D /* } */)) { - state.raise("Lone quantifier brackets"); - } - } - if (state.maxBackReference > state.numCapturingParens) { - state.raise("Invalid escape"); - } - for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) { - var name = list[i]; - - if (state.groupNames.indexOf(name) === -1) { - state.raise("Invalid named capture referenced"); - } - } - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction - pp$9.regexp_disjunction = function(state) { - var this$1 = this; - - this.regexp_alternative(state); - while (state.eat(0x7C /* | */)) { - this$1.regexp_alternative(state); - } - - // Make the same message as V8. - if (this.regexp_eatQuantifier(state, true)) { - state.raise("Nothing to repeat"); - } - if (state.eat(0x7B /* { */)) { - state.raise("Lone quantifier brackets"); - } - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative - pp$9.regexp_alternative = function(state) { - while (state.pos < state.source.length && this.regexp_eatTerm(state)) - { } - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term - pp$9.regexp_eatTerm = function(state) { - if (this.regexp_eatAssertion(state)) { - // Handle `QuantifiableAssertion Quantifier` alternative. - // `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion - // is a QuantifiableAssertion. - if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) { - // Make the same message as V8. - if (state.switchU) { - state.raise("Invalid quantifier"); - } - } - return true - } - - if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) { - this.regexp_eatQuantifier(state); - return true - } - - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion - pp$9.regexp_eatAssertion = function(state) { - var start = state.pos; - state.lastAssertionIsQuantifiable = false; - - // ^, $ - if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) { - return true - } - - // \b \B - if (state.eat(0x5C /* \ */)) { - if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) { - return true - } - state.pos = start; - } - - // Lookahead / Lookbehind - if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) { - var lookbehind = false; - if (this.options.ecmaVersion >= 9) { - lookbehind = state.eat(0x3C /* < */); - } - if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) { - this.regexp_disjunction(state); - if (!state.eat(0x29 /* ) */)) { - state.raise("Unterminated group"); - } - state.lastAssertionIsQuantifiable = !lookbehind; - return true - } - } - - state.pos = start; - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier - pp$9.regexp_eatQuantifier = function(state, noError) { - if ( noError === void 0 ) noError = false; - - if (this.regexp_eatQuantifierPrefix(state, noError)) { - state.eat(0x3F /* ? */); - return true - } - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix - pp$9.regexp_eatQuantifierPrefix = function(state, noError) { - return ( - state.eat(0x2A /* * */) || - state.eat(0x2B /* + */) || - state.eat(0x3F /* ? */) || - this.regexp_eatBracedQuantifier(state, noError) - ) - }; - pp$9.regexp_eatBracedQuantifier = function(state, noError) { - var start = state.pos; - if (state.eat(0x7B /* { */)) { - var min = 0, max = -1; - if (this.regexp_eatDecimalDigits(state)) { - min = state.lastIntValue; - if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) { - max = state.lastIntValue; - } - if (state.eat(0x7D /* } */)) { - // SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term - if (max !== -1 && max < min && !noError) { - state.raise("numbers out of order in {} quantifier"); - } - return true - } - } - if (state.switchU && !noError) { - state.raise("Incomplete quantifier"); - } - state.pos = start; - } - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-Atom - pp$9.regexp_eatAtom = function(state) { - return ( - this.regexp_eatPatternCharacters(state) || - state.eat(0x2E /* . */) || - this.regexp_eatReverseSolidusAtomEscape(state) || - this.regexp_eatCharacterClass(state) || - this.regexp_eatUncapturingGroup(state) || - this.regexp_eatCapturingGroup(state) - ) - }; - pp$9.regexp_eatReverseSolidusAtomEscape = function(state) { - var start = state.pos; - if (state.eat(0x5C /* \ */)) { - if (this.regexp_eatAtomEscape(state)) { - return true - } - state.pos = start; - } - return false - }; - pp$9.regexp_eatUncapturingGroup = function(state) { - var start = state.pos; - if (state.eat(0x28 /* ( */)) { - if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) { - this.regexp_disjunction(state); - if (state.eat(0x29 /* ) */)) { - return true - } - state.raise("Unterminated group"); - } - state.pos = start; - } - return false - }; - pp$9.regexp_eatCapturingGroup = function(state) { - if (state.eat(0x28 /* ( */)) { - if (this.options.ecmaVersion >= 9) { - this.regexp_groupSpecifier(state); - } else if (state.current() === 0x3F /* ? */) { - state.raise("Invalid group"); - } - this.regexp_disjunction(state); - if (state.eat(0x29 /* ) */)) { - state.numCapturingParens += 1; - return true - } - state.raise("Unterminated group"); - } - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom - pp$9.regexp_eatExtendedAtom = function(state) { - return ( - state.eat(0x2E /* . */) || - this.regexp_eatReverseSolidusAtomEscape(state) || - this.regexp_eatCharacterClass(state) || - this.regexp_eatUncapturingGroup(state) || - this.regexp_eatCapturingGroup(state) || - this.regexp_eatInvalidBracedQuantifier(state) || - this.regexp_eatExtendedPatternCharacter(state) - ) - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier - pp$9.regexp_eatInvalidBracedQuantifier = function(state) { - if (this.regexp_eatBracedQuantifier(state, true)) { - state.raise("Nothing to repeat"); - } - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter - pp$9.regexp_eatSyntaxCharacter = function(state) { - var ch = state.current(); - if (isSyntaxCharacter(ch)) { - state.lastIntValue = ch; - state.advance(); - return true - } - return false - }; - function isSyntaxCharacter(ch) { - return ( - ch === 0x24 /* $ */ || - ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ || - ch === 0x2E /* . */ || - ch === 0x3F /* ? */ || - ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ || - ch >= 0x7B /* { */ && ch <= 0x7D /* } */ - ) - } - - // https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter - // But eat eager. - pp$9.regexp_eatPatternCharacters = function(state) { - var start = state.pos; - var ch = 0; - while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) { - state.advance(); - } - return state.pos !== start - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter - pp$9.regexp_eatExtendedPatternCharacter = function(state) { - var ch = state.current(); - if ( - ch !== -1 && - ch !== 0x24 /* $ */ && - !(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) && - ch !== 0x2E /* . */ && - ch !== 0x3F /* ? */ && - ch !== 0x5B /* [ */ && - ch !== 0x5E /* ^ */ && - ch !== 0x7C /* | */ - ) { - state.advance(); - return true - } - return false - }; - - // GroupSpecifier[U] :: - // [empty] - // `?` GroupName[?U] - pp$9.regexp_groupSpecifier = function(state) { - if (state.eat(0x3F /* ? */)) { - if (this.regexp_eatGroupName(state)) { - if (state.groupNames.indexOf(state.lastStringValue) !== -1) { - state.raise("Duplicate capture group name"); - } - state.groupNames.push(state.lastStringValue); - return - } - state.raise("Invalid group"); - } - }; - - // GroupName[U] :: - // `<` RegExpIdentifierName[?U] `>` - // Note: this updates `state.lastStringValue` property with the eaten name. - pp$9.regexp_eatGroupName = function(state) { - state.lastStringValue = ""; - if (state.eat(0x3C /* < */)) { - if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) { - return true - } - state.raise("Invalid capture group name"); - } - return false - }; - - // RegExpIdentifierName[U] :: - // RegExpIdentifierStart[?U] - // RegExpIdentifierName[?U] RegExpIdentifierPart[?U] - // Note: this updates `state.lastStringValue` property with the eaten name. - pp$9.regexp_eatRegExpIdentifierName = function(state) { - state.lastStringValue = ""; - if (this.regexp_eatRegExpIdentifierStart(state)) { - state.lastStringValue += codePointToString$1(state.lastIntValue); - while (this.regexp_eatRegExpIdentifierPart(state)) { - state.lastStringValue += codePointToString$1(state.lastIntValue); - } - return true - } - return false - }; - - // RegExpIdentifierStart[U] :: - // UnicodeIDStart - // `$` - // `_` - // `\` RegExpUnicodeEscapeSequence[?U] - pp$9.regexp_eatRegExpIdentifierStart = function(state) { - var start = state.pos; - var ch = state.current(); - state.advance(); - - if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) { - ch = state.lastIntValue; - } - if (isRegExpIdentifierStart(ch)) { - state.lastIntValue = ch; - return true - } - - state.pos = start; - return false - }; - function isRegExpIdentifierStart(ch) { - return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ - } - - // RegExpIdentifierPart[U] :: - // UnicodeIDContinue - // `$` - // `_` - // `\` RegExpUnicodeEscapeSequence[?U] - // - // - pp$9.regexp_eatRegExpIdentifierPart = function(state) { - var start = state.pos; - var ch = state.current(); - state.advance(); - - if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state)) { - ch = state.lastIntValue; - } - if (isRegExpIdentifierPart(ch)) { - state.lastIntValue = ch; - return true - } - - state.pos = start; - return false - }; - function isRegExpIdentifierPart(ch) { - return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* */ || ch === 0x200D /* */ - } - - // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape - pp$9.regexp_eatAtomEscape = function(state) { - if ( - this.regexp_eatBackReference(state) || - this.regexp_eatCharacterClassEscape(state) || - this.regexp_eatCharacterEscape(state) || - (state.switchN && this.regexp_eatKGroupName(state)) - ) { - return true - } - if (state.switchU) { - // Make the same message as V8. - if (state.current() === 0x63 /* c */) { - state.raise("Invalid unicode escape"); - } - state.raise("Invalid escape"); - } - return false - }; - pp$9.regexp_eatBackReference = function(state) { - var start = state.pos; - if (this.regexp_eatDecimalEscape(state)) { - var n = state.lastIntValue; - if (state.switchU) { - // For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape - if (n > state.maxBackReference) { - state.maxBackReference = n; - } - return true - } - if (n <= state.numCapturingParens) { - return true - } - state.pos = start; - } - return false - }; - pp$9.regexp_eatKGroupName = function(state) { - if (state.eat(0x6B /* k */)) { - if (this.regexp_eatGroupName(state)) { - state.backReferenceNames.push(state.lastStringValue); - return true - } - state.raise("Invalid named reference"); - } - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape - pp$9.regexp_eatCharacterEscape = function(state) { - return ( - this.regexp_eatControlEscape(state) || - this.regexp_eatCControlLetter(state) || - this.regexp_eatZero(state) || - this.regexp_eatHexEscapeSequence(state) || - this.regexp_eatRegExpUnicodeEscapeSequence(state) || - (!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) || - this.regexp_eatIdentityEscape(state) - ) - }; - pp$9.regexp_eatCControlLetter = function(state) { - var start = state.pos; - if (state.eat(0x63 /* c */)) { - if (this.regexp_eatControlLetter(state)) { - return true - } - state.pos = start; - } - return false - }; - pp$9.regexp_eatZero = function(state) { - if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) { - state.lastIntValue = 0; - state.advance(); - return true - } - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape - pp$9.regexp_eatControlEscape = function(state) { - var ch = state.current(); - if (ch === 0x74 /* t */) { - state.lastIntValue = 0x09; /* \t */ - state.advance(); - return true - } - if (ch === 0x6E /* n */) { - state.lastIntValue = 0x0A; /* \n */ - state.advance(); - return true - } - if (ch === 0x76 /* v */) { - state.lastIntValue = 0x0B; /* \v */ - state.advance(); - return true - } - if (ch === 0x66 /* f */) { - state.lastIntValue = 0x0C; /* \f */ - state.advance(); - return true - } - if (ch === 0x72 /* r */) { - state.lastIntValue = 0x0D; /* \r */ - state.advance(); - return true - } - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter - pp$9.regexp_eatControlLetter = function(state) { - var ch = state.current(); - if (isControlLetter(ch)) { - state.lastIntValue = ch % 0x20; - state.advance(); - return true - } - return false - }; - function isControlLetter(ch) { - return ( - (ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) || - (ch >= 0x61 /* a */ && ch <= 0x7A /* z */) - ) - } - - // https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence - pp$9.regexp_eatRegExpUnicodeEscapeSequence = function(state) { - var start = state.pos; - - if (state.eat(0x75 /* u */)) { - if (this.regexp_eatFixedHexDigits(state, 4)) { - var lead = state.lastIntValue; - if (state.switchU && lead >= 0xD800 && lead <= 0xDBFF) { - var leadSurrogateEnd = state.pos; - if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) { - var trail = state.lastIntValue; - if (trail >= 0xDC00 && trail <= 0xDFFF) { - state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000; - return true - } - } - state.pos = leadSurrogateEnd; - state.lastIntValue = lead; - } - return true - } - if ( - state.switchU && - state.eat(0x7B /* { */) && - this.regexp_eatHexDigits(state) && - state.eat(0x7D /* } */) && - isValidUnicode(state.lastIntValue) - ) { - return true - } - if (state.switchU) { - state.raise("Invalid unicode escape"); - } - state.pos = start; - } - - return false - }; - function isValidUnicode(ch) { - return ch >= 0 && ch <= 0x10FFFF - } - - // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape - pp$9.regexp_eatIdentityEscape = function(state) { - if (state.switchU) { - if (this.regexp_eatSyntaxCharacter(state)) { - return true - } - if (state.eat(0x2F /* / */)) { - state.lastIntValue = 0x2F; /* / */ - return true - } - return false - } - - var ch = state.current(); - if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) { - state.lastIntValue = ch; - state.advance(); - return true - } - - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape - pp$9.regexp_eatDecimalEscape = function(state) { - state.lastIntValue = 0; - var ch = state.current(); - if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) { - do { - state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */); - state.advance(); - } while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) - return true - } - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape - pp$9.regexp_eatCharacterClassEscape = function(state) { - var ch = state.current(); - - if (isCharacterClassEscape(ch)) { - state.lastIntValue = -1; - state.advance(); - return true - } - - if ( - state.switchU && - this.options.ecmaVersion >= 9 && - (ch === 0x50 /* P */ || ch === 0x70 /* p */) - ) { - state.lastIntValue = -1; - state.advance(); - if ( - state.eat(0x7B /* { */) && - this.regexp_eatUnicodePropertyValueExpression(state) && - state.eat(0x7D /* } */) - ) { - return true - } - state.raise("Invalid property name"); - } - - return false - }; - function isCharacterClassEscape(ch) { - return ( - ch === 0x64 /* d */ || - ch === 0x44 /* D */ || - ch === 0x73 /* s */ || - ch === 0x53 /* S */ || - ch === 0x77 /* w */ || - ch === 0x57 /* W */ - ) - } - - // UnicodePropertyValueExpression :: - // UnicodePropertyName `=` UnicodePropertyValue - // LoneUnicodePropertyNameOrValue - pp$9.regexp_eatUnicodePropertyValueExpression = function(state) { - var start = state.pos; - - // UnicodePropertyName `=` UnicodePropertyValue - if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) { - var name = state.lastStringValue; - if (this.regexp_eatUnicodePropertyValue(state)) { - var value = state.lastStringValue; - this.regexp_validateUnicodePropertyNameAndValue(state, name, value); - return true - } - } - state.pos = start; - - // LoneUnicodePropertyNameOrValue - if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) { - var nameOrValue = state.lastStringValue; - this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue); - return true - } - return false - }; - pp$9.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) { - if (!data.hasOwnProperty(name) || data[name].indexOf(value) === -1) { - state.raise("Invalid property name"); - } - }; - pp$9.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) { - if (data.$LONE.indexOf(nameOrValue) === -1) { - state.raise("Invalid property name"); - } - }; - - // UnicodePropertyName :: - // UnicodePropertyNameCharacters - pp$9.regexp_eatUnicodePropertyName = function(state) { - var ch = 0; - state.lastStringValue = ""; - while (isUnicodePropertyNameCharacter(ch = state.current())) { - state.lastStringValue += codePointToString$1(ch); - state.advance(); - } - return state.lastStringValue !== "" - }; - function isUnicodePropertyNameCharacter(ch) { - return isControlLetter(ch) || ch === 0x5F /* _ */ - } - - // UnicodePropertyValue :: - // UnicodePropertyValueCharacters - pp$9.regexp_eatUnicodePropertyValue = function(state) { - var ch = 0; - state.lastStringValue = ""; - while (isUnicodePropertyValueCharacter(ch = state.current())) { - state.lastStringValue += codePointToString$1(ch); - state.advance(); - } - return state.lastStringValue !== "" - }; - function isUnicodePropertyValueCharacter(ch) { - return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch) - } - - // LoneUnicodePropertyNameOrValue :: - // UnicodePropertyValueCharacters - pp$9.regexp_eatLoneUnicodePropertyNameOrValue = function(state) { - return this.regexp_eatUnicodePropertyValue(state) - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass - pp$9.regexp_eatCharacterClass = function(state) { - if (state.eat(0x5B /* [ */)) { - state.eat(0x5E /* ^ */); - this.regexp_classRanges(state); - if (state.eat(0x5D /* [ */)) { - return true - } - // Unreachable since it threw "unterminated regular expression" error before. - state.raise("Unterminated character class"); - } - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges - // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges - // https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash - pp$9.regexp_classRanges = function(state) { - var this$1 = this; - - while (this.regexp_eatClassAtom(state)) { - var left = state.lastIntValue; - if (state.eat(0x2D /* - */) && this$1.regexp_eatClassAtom(state)) { - var right = state.lastIntValue; - if (state.switchU && (left === -1 || right === -1)) { - state.raise("Invalid character class"); - } - if (left !== -1 && right !== -1 && left > right) { - state.raise("Range out of order in character class"); - } - } - } - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom - // https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash - pp$9.regexp_eatClassAtom = function(state) { - var start = state.pos; - - if (state.eat(0x5C /* \ */)) { - if (this.regexp_eatClassEscape(state)) { - return true - } - if (state.switchU) { - // Make the same message as V8. - var ch$1 = state.current(); - if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) { - state.raise("Invalid class escape"); - } - state.raise("Invalid escape"); - } - state.pos = start; - } - - var ch = state.current(); - if (ch !== 0x5D /* [ */) { - state.lastIntValue = ch; - state.advance(); - return true - } - - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape - pp$9.regexp_eatClassEscape = function(state) { - var start = state.pos; - - if (state.eat(0x62 /* b */)) { - state.lastIntValue = 0x08; /* */ - return true - } - - if (state.switchU && state.eat(0x2D /* - */)) { - state.lastIntValue = 0x2D; /* - */ - return true - } - - if (!state.switchU && state.eat(0x63 /* c */)) { - if (this.regexp_eatClassControlLetter(state)) { - return true - } - state.pos = start; - } - - return ( - this.regexp_eatCharacterClassEscape(state) || - this.regexp_eatCharacterEscape(state) - ) - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter - pp$9.regexp_eatClassControlLetter = function(state) { - var ch = state.current(); - if (isDecimalDigit(ch) || ch === 0x5F /* _ */) { - state.lastIntValue = ch % 0x20; - state.advance(); - return true - } - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence - pp$9.regexp_eatHexEscapeSequence = function(state) { - var start = state.pos; - if (state.eat(0x78 /* x */)) { - if (this.regexp_eatFixedHexDigits(state, 2)) { - return true - } - if (state.switchU) { - state.raise("Invalid escape"); - } - state.pos = start; - } - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits - pp$9.regexp_eatDecimalDigits = function(state) { - var start = state.pos; - var ch = 0; - state.lastIntValue = 0; - while (isDecimalDigit(ch = state.current())) { - state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */); - state.advance(); - } - return state.pos !== start - }; - function isDecimalDigit(ch) { - return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */ - } - - // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits - pp$9.regexp_eatHexDigits = function(state) { - var start = state.pos; - var ch = 0; - state.lastIntValue = 0; - while (isHexDigit(ch = state.current())) { - state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch); - state.advance(); - } - return state.pos !== start - }; - function isHexDigit(ch) { - return ( - (ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) || - (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) || - (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) - ) - } - function hexToInt(ch) { - if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) { - return 10 + (ch - 0x41 /* A */) - } - if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) { - return 10 + (ch - 0x61 /* a */) - } - return ch - 0x30 /* 0 */ - } - - // https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence - // Allows only 0-377(octal) i.e. 0-255(decimal). - pp$9.regexp_eatLegacyOctalEscapeSequence = function(state) { - if (this.regexp_eatOctalDigit(state)) { - var n1 = state.lastIntValue; - if (this.regexp_eatOctalDigit(state)) { - var n2 = state.lastIntValue; - if (n1 <= 3 && this.regexp_eatOctalDigit(state)) { - state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue; - } else { - state.lastIntValue = n1 * 8 + n2; - } - } else { - state.lastIntValue = n1; - } - return true - } - return false - }; - - // https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit - pp$9.regexp_eatOctalDigit = function(state) { - var ch = state.current(); - if (isOctalDigit(ch)) { - state.lastIntValue = ch - 0x30; /* 0 */ - state.advance(); - return true - } - state.lastIntValue = 0; - return false - }; - function isOctalDigit(ch) { - return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */ - } - - // https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits - // https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit - // And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence - pp$9.regexp_eatFixedHexDigits = function(state, length) { - var start = state.pos; - state.lastIntValue = 0; - for (var i = 0; i < length; ++i) { - var ch = state.current(); - if (!isHexDigit(ch)) { - state.pos = start; - return false - } - state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch); - state.advance(); - } - return true - }; - - // Object type used to represent tokens. Note that normally, tokens - // simply exist as properties on the parser object. This is only - // used for the onToken callback and the external tokenizer. - - var Token = function Token(p) { - this.type = p.type; - this.value = p.value; - this.start = p.start; - this.end = p.end; - if (p.options.locations) - { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); } - if (p.options.ranges) - { this.range = [p.start, p.end]; } - }; - - // ## Tokenizer - - var pp$8 = Parser.prototype; - - // Move to the next token - - pp$8.next = function() { - if (this.options.onToken) - { this.options.onToken(new Token(this)); } - - this.lastTokEnd = this.end; - this.lastTokStart = this.start; - this.lastTokEndLoc = this.endLoc; - this.lastTokStartLoc = this.startLoc; - this.nextToken(); - }; - - pp$8.getToken = function() { - this.next(); - return new Token(this) - }; - - // If we're in an ES6 environment, make parsers iterable - if (typeof Symbol !== "undefined") - { pp$8[Symbol.iterator] = function() { - var this$1 = this; - - return { - next: function () { - var token = this$1.getToken(); - return { - done: token.type === types.eof, - value: token - } - } - } - }; } - - // Toggle strict mode. Re-reads the next number or string to please - // pedantic tests (`"use strict"; 010;` should fail). - - pp$8.curContext = function() { - return this.context[this.context.length - 1] - }; - - // Read a single token, updating the parser object's token-related - // properties. - - pp$8.nextToken = function() { - var curContext = this.curContext(); - if (!curContext || !curContext.preserveSpace) { this.skipSpace(); } - - this.start = this.pos; - if (this.options.locations) { this.startLoc = this.curPosition(); } - if (this.pos >= this.input.length) { return this.finishToken(types.eof) } - - if (curContext.override) { return curContext.override(this) } - else { this.readToken(this.fullCharCodeAtPos()); } - }; - - pp$8.readToken = function(code) { - // Identifier or keyword. '\uXXXX' sequences are allowed in - // identifiers, so '\' also dispatches to that. - if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */) - { return this.readWord() } - - return this.getTokenFromCode(code) - }; - - pp$8.fullCharCodeAtPos = function() { - var code = this.input.charCodeAt(this.pos); - if (code <= 0xd7ff || code >= 0xe000) { return code } - var next = this.input.charCodeAt(this.pos + 1); - return (code << 10) + next - 0x35fdc00 - }; - - pp$8.skipBlockComment = function() { - var this$1 = this; - - var startLoc = this.options.onComment && this.curPosition(); - var start = this.pos, end = this.input.indexOf("*/", this.pos += 2); - if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); } - this.pos = end + 2; - if (this.options.locations) { - lineBreakG.lastIndex = start; - var match; - while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) { - ++this$1.curLine; - this$1.lineStart = match.index + match[0].length; - } - } - if (this.options.onComment) - { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos, - startLoc, this.curPosition()); } - }; - - pp$8.skipLineComment = function(startSkip) { - var this$1 = this; - - var start = this.pos; - var startLoc = this.options.onComment && this.curPosition(); - var ch = this.input.charCodeAt(this.pos += startSkip); - while (this.pos < this.input.length && !isNewLine(ch)) { - ch = this$1.input.charCodeAt(++this$1.pos); - } - if (this.options.onComment) - { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos, - startLoc, this.curPosition()); } - }; - - // Called at the start of the parse and after every token. Skips - // whitespace and comments, and. - - pp$8.skipSpace = function() { - var this$1 = this; - - loop: while (this.pos < this.input.length) { - var ch = this$1.input.charCodeAt(this$1.pos); - switch (ch) { - case 32: case 160: // ' ' - ++this$1.pos; - break - case 13: - if (this$1.input.charCodeAt(this$1.pos + 1) === 10) { - ++this$1.pos; - } - case 10: case 8232: case 8233: - ++this$1.pos; - if (this$1.options.locations) { - ++this$1.curLine; - this$1.lineStart = this$1.pos; - } - break - case 47: // '/' - switch (this$1.input.charCodeAt(this$1.pos + 1)) { - case 42: // '*' - this$1.skipBlockComment(); - break - case 47: - this$1.skipLineComment(2); - break - default: - break loop - } - break - default: - if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) { - ++this$1.pos; - } else { - break loop - } - } - } - }; - - // Called at the end of every token. Sets `end`, `val`, and - // maintains `context` and `exprAllowed`, and skips the space after - // the token, so that the next one's `start` will point at the - // right position. - - pp$8.finishToken = function(type, val) { - this.end = this.pos; - if (this.options.locations) { this.endLoc = this.curPosition(); } - var prevType = this.type; - this.type = type; - this.value = val; - - this.updateContext(prevType); - }; - - // ### Token reading - - // This is the function that is called to fetch the next token. It - // is somewhat obscure, because it works in character codes rather - // than characters, and because operator parsing has been inlined - // into it. - // - // All in the name of speed. - // - pp$8.readToken_dot = function() { - var next = this.input.charCodeAt(this.pos + 1); - if (next >= 48 && next <= 57) { return this.readNumber(true) } - var next2 = this.input.charCodeAt(this.pos + 2); - if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.' - this.pos += 3; - return this.finishToken(types.ellipsis) - } else { - ++this.pos; - return this.finishToken(types.dot) - } - }; - - pp$8.readToken_slash = function() { // '/' - var next = this.input.charCodeAt(this.pos + 1); - if (this.exprAllowed) { ++this.pos; return this.readRegexp() } - if (next === 61) { return this.finishOp(types.assign, 2) } - return this.finishOp(types.slash, 1) - }; - - pp$8.readToken_mult_modulo_exp = function(code) { // '%*' - var next = this.input.charCodeAt(this.pos + 1); - var size = 1; - var tokentype = code === 42 ? types.star : types.modulo; - - // exponentiation operator ** and **= - if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) { - ++size; - tokentype = types.starstar; - next = this.input.charCodeAt(this.pos + 2); - } - - if (next === 61) { return this.finishOp(types.assign, size + 1) } - return this.finishOp(tokentype, size) - }; - - pp$8.readToken_pipe_amp = function(code) { // '|&' - var next = this.input.charCodeAt(this.pos + 1); - if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) } - if (next === 61) { return this.finishOp(types.assign, 2) } - return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1) - }; - - pp$8.readToken_caret = function() { // '^' - var next = this.input.charCodeAt(this.pos + 1); - if (next === 61) { return this.finishOp(types.assign, 2) } - return this.finishOp(types.bitwiseXOR, 1) - }; - - pp$8.readToken_plus_min = function(code) { // '+-' - var next = this.input.charCodeAt(this.pos + 1); - if (next === code) { - if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 && - (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) { - // A `-->` line comment - this.skipLineComment(3); - this.skipSpace(); - return this.nextToken() - } - return this.finishOp(types.incDec, 2) - } - if (next === 61) { return this.finishOp(types.assign, 2) } - return this.finishOp(types.plusMin, 1) - }; - - pp$8.readToken_lt_gt = function(code) { // '<>' - var next = this.input.charCodeAt(this.pos + 1); - var size = 1; - if (next === code) { - size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2; - if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) } - return this.finishOp(types.bitShift, size) - } - if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 && - this.input.charCodeAt(this.pos + 3) === 45) { - // `