UNPKG

prepack

Version:

Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.

78 lines (65 loc) 3.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAsPropertyNameExpression = getAsPropertyNameExpression; exports.memberExpressionHelper = memberExpressionHelper; exports.optionalStringOfLocation = optionalStringOfLocation; exports.stringOfLocation = stringOfLocation; exports.protoExpression = exports.constructorExpression = exports.emptyExpression = exports.nullExpression = exports.voidExpression = void 0; var t = _interopRequireWildcard(require("@babel/types")); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } /** * Copyright (c) 2017-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ const voidExpression = t.unaryExpression("void", t.numericLiteral(0), true); exports.voidExpression = voidExpression; const nullExpression = t.nullLiteral(); exports.nullExpression = nullExpression; const emptyExpression = t.identifier("__empty"); exports.emptyExpression = emptyExpression; const constructorExpression = t.identifier("__constructor"); exports.constructorExpression = constructorExpression; const protoExpression = t.identifier("__proto__"); exports.protoExpression = protoExpression; function getAsPropertyNameExpression(key, canBeIdentifier = true) { // If key is a non-negative numeric string literal, parse it and set it as a numeric index instead. let index = Number.parseInt(key, 10); if (index >= 0 && index.toString() === key) { return t.numericLiteral(index); } if (canBeIdentifier) { // TODO #1020: revert this when Unicode identifiers are supported by all targetted JavaScript engines let keyIsAscii = /^[\u0000-\u007f]*$/.test(key); if (t.isValidIdentifier(key) && keyIsAscii) return t.identifier(key); } return t.stringLiteral(key); } function memberExpressionHelper(object, property) { let propertyExpression; let computed; if (typeof property === "string") { propertyExpression = getAsPropertyNameExpression(property); computed = !t.isIdentifier(propertyExpression); } else if (t.isStringLiteral(property)) { propertyExpression = getAsPropertyNameExpression(property.value); computed = !t.isIdentifier(propertyExpression); } else { propertyExpression = property; computed = true; } return t.memberExpression(object, propertyExpression, computed); } function optionalStringOfLocation(location) { // if we can't get a value, then it's likely that the source file was not given return location ? ` at location ${stringOfLocation(location)}` : ""; } function stringOfLocation(location) { return `${location.source || "(unknown source file)"}[${location.start.line}:${location.start.column}]`; } //# sourceMappingURL=babelhelpers.js.map