Commit a2e8cafb authored by patri's avatar patri
Browse files

Test New PC

1 merge request!1update some ui
Showing with 791 additions and 444 deletions
+791 -444
......@@ -5,11 +5,7 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = _default;
var t = _interopRequireWildcard(require("@babel/types"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var t = require("@babel/types");
function _default(node) {
const params = node.params;
......
{
"_from": "@babel/helper-get-function-arity@^7.7.0",
"_id": "@babel/helper-get-function-arity@7.7.0",
"_inBundle": false,
"_integrity": "sha512-tLdojOTz4vWcEnHWHCuPN5P85JLZWbm5Fx5ZsMEMPhF3Uoe3O7awrbM2nQ04bDOUToH/2tH/ezKEOR8zEYzqyw==",
"_location": "/@babel/helper-get-function-arity",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@babel/helper-get-function-arity@^7.7.0",
"name": "@babel/helper-get-function-arity",
"escapedName": "@babel%2fhelper-get-function-arity",
"scope": "@babel",
"rawSpec": "^7.7.0",
"saveSpec": null,
"fetchSpec": "^7.7.0"
},
"_requiredBy": [
"/@babel/helper-function-name",
"/@babel/plugin-transform-parameters"
],
"_resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.7.0.tgz",
"_shasum": "c604886bc97287a1d1398092bc666bc3d7d7aa2d",
"_spec": "@babel/helper-get-function-arity@^7.7.0",
"_where": "C:\\Work\\OneDrive - bwstaff\\M4_Lab\\TV3\\NewVersion01\\LAFJLBmf939XYm5gj\\dev\\node_modules\\@babel\\helper-function-name",
"bundleDependencies": false,
"dependencies": {
"@babel/types": "^7.7.0"
},
"deprecated": false,
"name": "@babel/helper-get-function-arity",
"version": "7.14.5",
"description": "Helper function to get function arity",
"gitHead": "97faa83953cb87e332554fa559a4956d202343ea",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-helper-get-function-arity"
},
"homepage": "https://babel.dev/docs/en/next/babel-helper-get-function-arity",
"license": "MIT",
"main": "lib/index.js",
"name": "@babel/helper-get-function-arity",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-helper-get-function-arity"
"main": "./lib/index.js",
"dependencies": {
"@babel/types": "^7.14.5"
},
"engines": {
"node": ">=6.9.0"
},
"version": "7.7.0"
}
"author": "The Babel Team (https://babel.dev/team)"
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
> Helper function to hoist variables
See our website [@babel/helper-hoist-variables](https://babeljs.io/docs/en/next/babel-helper-hoist-variables.html) for more information.
See our website [@babel/helper-hoist-variables](https://babeljs.io/docs/en/babel-helper-hoist-variables) for more information.
## Install
......
......@@ -3,20 +3,16 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
exports.default = hoistVariables;
var t = _interopRequireWildcard(require("@babel/types"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var t = require("@babel/types");
const visitor = {
Scope(path, state) {
if (state.kind === "let") path.skip();
},
Function(path) {
FunctionParent(path) {
path.skip();
},
......@@ -49,7 +45,7 @@ const visitor = {
};
function _default(path, emit, kind = "var") {
function hoistVariables(path, emit, kind = "var") {
path.traverse(visitor, {
kind,
emit
......
{
"_from": "@babel/helper-hoist-variables@^7.7.0",
"_id": "@babel/helper-hoist-variables@7.7.0",
"_inBundle": false,
"_integrity": "sha512-LUe/92NqsDAkJjjCEWkNe+/PcpnisvnqdlRe19FahVapa4jndeuJ+FBiTX1rcAKWKcJGE+C3Q3tuEuxkSmCEiQ==",
"_location": "/@babel/helper-hoist-variables",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@babel/helper-hoist-variables@^7.7.0",
"name": "@babel/helper-hoist-variables",
"escapedName": "@babel%2fhelper-hoist-variables",
"scope": "@babel",
"rawSpec": "^7.7.0",
"saveSpec": null,
"fetchSpec": "^7.7.0"
},
"_requiredBy": [
"/@babel/helper-call-delegate",
"/@babel/plugin-transform-modules-systemjs"
],
"_resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.7.0.tgz",
"_shasum": "b4552e4cfe5577d7de7b183e193e84e4ec538c81",
"_spec": "@babel/helper-hoist-variables@^7.7.0",
"_where": "C:\\Work\\OneDrive - bwstaff\\M4_Lab\\TV3\\NewVersion01\\LAFJLBmf939XYm5gj\\dev\\node_modules\\@babel\\plugin-transform-modules-systemjs",
"bundleDependencies": false,
"dependencies": {
"@babel/types": "^7.7.0"
},
"deprecated": false,
"name": "@babel/helper-hoist-variables",
"version": "7.14.5",
"description": "Helper function to hoist variables",
"gitHead": "97faa83953cb87e332554fa559a4956d202343ea",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-helper-hoist-variables"
},
"homepage": "https://babel.dev/docs/en/next/babel-helper-hoist-variables",
"license": "MIT",
"main": "lib/index.js",
"name": "@babel/helper-hoist-variables",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-helper-hoist-variables"
"main": "./lib/index.js",
"dependencies": {
"@babel/types": "^7.14.5"
},
"TODO": "The @babel/traverse dependency is only needed for the NodePath TS type. We can consider exporting it from @babel/core.",
"devDependencies": {
"@babel/traverse": "7.14.5"
},
"engines": {
"node": ">=6.9.0"
},
"version": "7.7.0"
}
"author": "The Babel Team (https://babel.dev/team)"
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
> Helper function to replace certain member expressions with function calls
See our website [@babel/helper-member-expression-to-functions](https://babeljs.io/docs/en/next/babel-helper-member-expression-to-functions.html) for more information.
See our website [@babel/helper-member-expression-to-functions](https://babeljs.io/docs/en/babel-helper-member-expression-to-functions) for more information.
## Install
......
"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = memberExpressionToFunctions;
Object.defineProperty(exports, '__esModule', { value: true });
var t = require('@babel/types');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var t__namespace = /*#__PURE__*/_interopNamespace(t);
var t = _interopRequireWildcard(require("@babel/types"));
function willPathCastToBoolean(path) {
const maybeWrapped = path;
const {
node,
parentPath
} = maybeWrapped;
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
if (parentPath.isLogicalExpression()) {
const {
operator,
right
} = parentPath.node;
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
if (operator === "&&" || operator === "||" || operator === "??" && node === right) {
return willPathCastToBoolean(parentPath);
}
}
if (parentPath.isSequenceExpression()) {
const {
expressions
} = parentPath.node;
if (expressions[expressions.length - 1] === node) {
return willPathCastToBoolean(parentPath);
} else {
return true;
}
}
return parentPath.isConditional({
test: node
}) || parentPath.isUnaryExpression({
operator: "!"
}) || parentPath.isLoop({
test: node
});
}
class AssignmentMemoiser {
constructor() {
this._map = void 0;
this._map = new WeakMap();
}
......@@ -31,7 +86,7 @@ class AssignmentMemoiser {
record.count--;
if (record.count === 0) {
return t.assignmentExpression("=", value, key);
return t__namespace.assignmentExpression("=", value, key);
}
return value;
......@@ -46,25 +101,234 @@ class AssignmentMemoiser {
}
function toNonOptional(path, base) {
const {
node
} = path;
if (path.isOptionalMemberExpression()) {
return t__namespace.memberExpression(base, node.property, node.computed);
}
if (path.isOptionalCallExpression()) {
const callee = path.get("callee");
if (path.node.optional && callee.isOptionalMemberExpression()) {
const {
object
} = callee.node;
const context = path.scope.maybeGenerateMemoised(object) || object;
callee.get("object").replaceWith(t__namespace.assignmentExpression("=", context, object));
return t__namespace.callExpression(t__namespace.memberExpression(base, t__namespace.identifier("call")), [context, ...node.arguments]);
}
return t__namespace.callExpression(base, node.arguments);
}
return path.node;
}
function isInDetachedTree(path) {
while (path) {
if (path.isProgram()) break;
const {
parentPath,
container,
listKey
} = path;
const parentNode = parentPath.node;
if (listKey) {
if (container !== parentNode[listKey]) return true;
} else {
if (container !== parentNode) return true;
}
path = parentPath;
}
return false;
}
const handle = {
memoise() {},
handle(member) {
handle(member, noDocumentAll) {
const {
node,
parent,
parentPath
parentPath,
scope
} = member;
if (member.isOptionalMemberExpression()) {
if (isInDetachedTree(member)) return;
const endPath = member.find(({
node,
parent,
parentPath
}) => {
if (parentPath.isOptionalMemberExpression()) {
return parent.optional || parent.object !== node;
}
if (parentPath.isOptionalCallExpression()) {
return node !== member.node && parent.optional || parent.callee !== node;
}
return true;
});
if (scope.path.isPattern()) {
endPath.replaceWith(t__namespace.callExpression(t__namespace.arrowFunctionExpression([], endPath.node), []));
return;
}
const willEndPathCastToBoolean = willPathCastToBoolean(endPath);
const rootParentPath = endPath.parentPath;
if (rootParentPath.isUpdateExpression({
argument: node
}) || rootParentPath.isAssignmentExpression({
left: node
})) {
throw member.buildCodeFrameError(`can't handle assignment`);
}
const isDeleteOperation = rootParentPath.isUnaryExpression({
operator: "delete"
});
if (isDeleteOperation && endPath.isOptionalMemberExpression() && endPath.get("property").isPrivateName()) {
throw member.buildCodeFrameError(`can't delete a private class element`);
}
let startingOptional = member;
for (;;) {
if (startingOptional.isOptionalMemberExpression()) {
if (startingOptional.node.optional) break;
startingOptional = startingOptional.get("object");
continue;
} else if (startingOptional.isOptionalCallExpression()) {
if (startingOptional.node.optional) break;
startingOptional = startingOptional.get("callee");
continue;
}
throw new Error(`Internal error: unexpected ${startingOptional.node.type}`);
}
const startingProp = startingOptional.isOptionalMemberExpression() ? "object" : "callee";
const startingNode = startingOptional.node[startingProp];
const baseNeedsMemoised = scope.maybeGenerateMemoised(startingNode);
const baseRef = baseNeedsMemoised != null ? baseNeedsMemoised : startingNode;
const parentIsOptionalCall = parentPath.isOptionalCallExpression({
callee: node
});
const parentIsCall = parentPath.isCallExpression({
callee: node
});
startingOptional.replaceWith(toNonOptional(startingOptional, baseRef));
if (parentIsOptionalCall) {
if (parent.optional) {
parentPath.replaceWith(this.optionalCall(member, parent.arguments));
} else {
parentPath.replaceWith(this.call(member, parent.arguments));
}
} else if (parentIsCall) {
member.replaceWith(this.boundGet(member));
} else {
member.replaceWith(this.get(member));
}
let regular = member.node;
for (let current = member; current !== endPath;) {
const {
parentPath
} = current;
if (parentPath === endPath && parentIsOptionalCall && parent.optional) {
regular = parentPath.node;
break;
}
regular = toNonOptional(parentPath, regular);
current = parentPath;
}
let context;
const endParentPath = endPath.parentPath;
if (t__namespace.isMemberExpression(regular) && endParentPath.isOptionalCallExpression({
callee: endPath.node,
optional: true
})) {
const {
object
} = regular;
context = member.scope.maybeGenerateMemoised(object);
if (context) {
regular.object = t__namespace.assignmentExpression("=", context, object);
}
}
let replacementPath = endPath;
if (isDeleteOperation) {
replacementPath = endParentPath;
regular = endParentPath.node;
}
const baseMemoised = baseNeedsMemoised ? t__namespace.assignmentExpression("=", t__namespace.cloneNode(baseRef), t__namespace.cloneNode(startingNode)) : t__namespace.cloneNode(baseRef);
if (willEndPathCastToBoolean) {
let nonNullishCheck;
if (noDocumentAll) {
nonNullishCheck = t__namespace.binaryExpression("!=", baseMemoised, t__namespace.nullLiteral());
} else {
nonNullishCheck = t__namespace.logicalExpression("&&", t__namespace.binaryExpression("!==", baseMemoised, t__namespace.nullLiteral()), t__namespace.binaryExpression("!==", t__namespace.cloneNode(baseRef), scope.buildUndefinedNode()));
}
replacementPath.replaceWith(t__namespace.logicalExpression("&&", nonNullishCheck, regular));
} else {
let nullishCheck;
if (noDocumentAll) {
nullishCheck = t__namespace.binaryExpression("==", baseMemoised, t__namespace.nullLiteral());
} else {
nullishCheck = t__namespace.logicalExpression("||", t__namespace.binaryExpression("===", baseMemoised, t__namespace.nullLiteral()), t__namespace.binaryExpression("===", t__namespace.cloneNode(baseRef), scope.buildUndefinedNode()));
}
replacementPath.replaceWith(t__namespace.conditionalExpression(nullishCheck, isDeleteOperation ? t__namespace.booleanLiteral(true) : scope.buildUndefinedNode(), regular));
}
if (context) {
const endParent = endParentPath.node;
endParentPath.replaceWith(t__namespace.optionalCallExpression(t__namespace.optionalMemberExpression(endParent.callee, t__namespace.identifier("call"), false, true), [t__namespace.cloneNode(context), ...endParent.arguments], false));
}
return;
}
if (parentPath.isUpdateExpression({
argument: node
})) {
if (this.simpleSet) {
member.replaceWith(this.simpleSet(member));
return;
}
const {
operator,
prefix
} = parent;
this.memoise(member, 2);
const value = t.binaryExpression(operator[0], t.unaryExpression("+", this.get(member)), t.numericLiteral(1));
const value = t__namespace.binaryExpression(operator[0], t__namespace.unaryExpression("+", this.get(member)), t__namespace.numericLiteral(1));
if (prefix) {
parentPath.replaceWith(this.set(member, value));
......@@ -76,8 +340,8 @@ const handle = {
scope.push({
id: ref
});
value.left = t.assignmentExpression("=", t.cloneNode(ref), value.left);
parentPath.replaceWith(t.sequenceExpression([this.set(member, value), t.cloneNode(ref)]));
value.left = t__namespace.assignmentExpression("=", t__namespace.cloneNode(ref), value.left);
parentPath.replaceWith(t__namespace.sequenceExpression([this.set(member, value), t__namespace.cloneNode(ref)]));
}
return;
......@@ -86,32 +350,55 @@ const handle = {
if (parentPath.isAssignmentExpression({
left: node
})) {
if (this.simpleSet) {
member.replaceWith(this.simpleSet(member));
return;
}
const {
operator,
right
right: value
} = parent;
let value = right;
if (operator !== "=") {
this.memoise(member, 2);
value = t.binaryExpression(operator.slice(0, -1), this.get(member), value);
if (operator === "=") {
parentPath.replaceWith(this.set(member, value));
} else {
const operatorTrunc = operator.slice(0, -1);
if (t__namespace.LOGICAL_OPERATORS.includes(operatorTrunc)) {
this.memoise(member, 1);
parentPath.replaceWith(t__namespace.logicalExpression(operatorTrunc, this.get(member), this.set(member, value)));
} else {
this.memoise(member, 2);
parentPath.replaceWith(this.set(member, t__namespace.binaryExpression(operatorTrunc, this.get(member), value)));
}
}
parentPath.replaceWith(this.set(member, value));
return;
}
if (parentPath.isCallExpression({
callee: node
})) {
const {
arguments: args
} = parent;
parentPath.replaceWith(this.call(member, args));
parentPath.replaceWith(this.call(member, parent.arguments));
return;
}
if (parentPath.isObjectProperty({
if (parentPath.isOptionalCallExpression({
callee: node
})) {
if (scope.path.isPattern()) {
parentPath.replaceWith(t__namespace.callExpression(t__namespace.arrowFunctionExpression([], parentPath.node), []));
return;
}
parentPath.replaceWith(this.optionalCall(member, parent.arguments));
return;
}
if (parentPath.isForXStatement({
left: node
}) || parentPath.isObjectProperty({
value: node
}) && parentPath.parentPath.isObjectPattern() || parentPath.isAssignmentPattern({
left: node
......@@ -128,9 +415,11 @@ const handle = {
}
};
function memberExpressionToFunctions(path, visitor, state) {
path.traverse(visitor, Object.assign({}, handle, {}, state, {
path.traverse(visitor, Object.assign({}, handle, state, {
memoiser: new AssignmentMemoiser()
}));
}
\ No newline at end of file
}
exports.default = memberExpressionToFunctions;
//# sourceMappingURL=index.js.map
{
"_from": "@babel/helper-member-expression-to-functions@^7.7.0",
"_id": "@babel/helper-member-expression-to-functions@7.7.0",
"_inBundle": false,
"_integrity": "sha512-QaCZLO2RtBcmvO/ekOLp8p7R5X2JriKRizeDpm5ChATAFWrrYDcDxPuCIBXKyBjY+i1vYSdcUTMIb8psfxHDPA==",
"_location": "/@babel/helper-member-expression-to-functions",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@babel/helper-member-expression-to-functions@^7.7.0",
"name": "@babel/helper-member-expression-to-functions",
"escapedName": "@babel%2fhelper-member-expression-to-functions",
"scope": "@babel",
"rawSpec": "^7.7.0",
"saveSpec": null,
"fetchSpec": "^7.7.0"
},
"_requiredBy": [
"/@babel/helper-create-class-features-plugin",
"/@babel/helper-replace-supers"
],
"_resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.7.0.tgz",
"_shasum": "472b93003a57071f95a541ea6c2b098398bcad8a",
"_spec": "@babel/helper-member-expression-to-functions@^7.7.0",
"_where": "C:\\Work\\OneDrive - bwstaff\\M4_Lab\\TV3\\NewVersion01\\LAFJLBmf939XYm5gj\\dev\\node_modules\\@babel\\helper-create-class-features-plugin",
"author": {
"name": "Justin Ridgewell",
"email": "justin@ridgewell.name"
},
"bundleDependencies": false,
"dependencies": {
"@babel/types": "^7.7.0"
},
"deprecated": false,
"name": "@babel/helper-member-expression-to-functions",
"version": "7.14.5",
"description": "Helper function to replace certain member expressions with function calls",
"gitHead": "97faa83953cb87e332554fa559a4956d202343ea",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-helper-member-expression-to-functions"
},
"homepage": "https://babel.dev/docs/en/next/babel-helper-member-expression-to-functions",
"license": "MIT",
"main": "lib/index.js",
"name": "@babel/helper-member-expression-to-functions",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-helper-member-expression-to-functions"
"main": "./lib/index.js",
"author": "The Babel Team (https://babel.dev/team)",
"dependencies": {
"@babel/types": "^7.14.5"
},
"devDependencies": {
"@babel/traverse": "7.14.5"
},
"version": "7.7.0"
}
"engines": {
"node": ">=6.9.0"
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
> Babel helper functions for inserting module loads
See our website [@babel/helper-module-imports](https://babeljs.io/docs/en/next/babel-helper-module-imports.html) for more information.
See our website [@babel/helper-module-imports](https://babeljs.io/docs/en/babel-helper-module-imports) for more information.
## Install
......
......@@ -5,15 +5,9 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = void 0;
var _assert = _interopRequireDefault(require("assert"));
var _assert = require("assert");
var t = _interopRequireWildcard(require("@babel/types"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var t = require("@babel/types");
class ImportBuilder {
constructor(importedSource, scope, hub) {
......@@ -21,6 +15,7 @@ class ImportBuilder {
this._resultName = null;
this._scope = null;
this._hub = null;
this._importedSource = void 0;
this._scope = scope;
this._hub = hub;
this._importedSource = importedSource;
......@@ -46,20 +41,27 @@ class ImportBuilder {
}
namespace(name = "namespace") {
name = this._scope.generateUidIdentifier(name);
const local = this._scope.generateUidIdentifier(name);
const statement = this._statements[this._statements.length - 1];
(0, _assert.default)(statement.type === "ImportDeclaration");
(0, _assert.default)(statement.specifiers.length === 0);
statement.specifiers = [t.importNamespaceSpecifier(name)];
this._resultName = t.cloneNode(name);
_assert(statement.type === "ImportDeclaration");
_assert(statement.specifiers.length === 0);
statement.specifiers = [t.importNamespaceSpecifier(local)];
this._resultName = t.cloneNode(local);
return this;
}
default(name) {
name = this._scope.generateUidIdentifier(name);
const statement = this._statements[this._statements.length - 1];
(0, _assert.default)(statement.type === "ImportDeclaration");
(0, _assert.default)(statement.specifiers.length === 0);
_assert(statement.type === "ImportDeclaration");
_assert(statement.specifiers.length === 0);
statement.specifiers = [t.importDefaultSpecifier(name)];
this._resultName = t.cloneNode(name);
return this;
......@@ -69,8 +71,11 @@ class ImportBuilder {
if (importName === "default") return this.default(name);
name = this._scope.generateUidIdentifier(name);
const statement = this._statements[this._statements.length - 1];
(0, _assert.default)(statement.type === "ImportDeclaration");
(0, _assert.default)(statement.specifiers.length === 0);
_assert(statement.type === "ImportDeclaration");
_assert(statement.specifiers.length === 0);
statement.specifiers = [t.importSpecifier(name, t.identifier(importName))];
this._resultName = t.cloneNode(name);
return this;
......@@ -81,7 +86,8 @@ class ImportBuilder {
let statement = this._statements[this._statements.length - 1];
if (statement.type !== "ExpressionStatement") {
(0, _assert.default)(this._resultName);
_assert(this._resultName);
statement = t.expressionStatement(this._resultName);
this._statements.push(statement);
......@@ -106,10 +112,11 @@ class ImportBuilder {
if (statement.type === "ExpressionStatement") {
statement.expression = t.callExpression(callee, [statement.expression]);
} else if (statement.type === "VariableDeclaration") {
(0, _assert.default)(statement.declarations.length === 1);
_assert(statement.declarations.length === 1);
statement.declarations[0].init = t.callExpression(callee, [statement.declarations[0].init]);
} else {
_assert.default.fail("Unexpected type.");
_assert.fail("Unexpected type.");
}
return this;
......@@ -121,10 +128,11 @@ class ImportBuilder {
if (statement.type === "ExpressionStatement") {
statement.expression = t.memberExpression(statement.expression, t.identifier(name));
} else if (statement.type === "VariableDeclaration") {
(0, _assert.default)(statement.declarations.length === 1);
_assert(statement.declarations.length === 1);
statement.declarations[0].init = t.memberExpression(statement.declarations[0].init, t.identifier(name));
} else {
_assert.default.fail("Unexpected type:" + statement.type);
_assert.fail("Unexpected type:" + statement.type);
}
return this;
......
......@@ -5,19 +5,13 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = void 0;
var _assert = _interopRequireDefault(require("assert"));
var _assert = require("assert");
var t = _interopRequireWildcard(require("@babel/types"));
var t = require("@babel/types");
var _importBuilder = _interopRequireDefault(require("./import-builder"));
var _importBuilder = require("./import-builder");
var _isModule = _interopRequireDefault(require("./is-module"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _isModule = require("./is-module");
class ImportInjector {
constructor(path, importedSource, opts) {
......@@ -27,7 +21,8 @@ class ImportInjector {
importedInterop: "babel",
importingInterop: "babel",
ensureLiveReference: false,
ensureNoContext: false
ensureNoContext: false,
importPosition: "before"
};
const programPath = path.find(p => p.isProgram());
this._programPath = programPath;
......@@ -41,7 +36,8 @@ class ImportInjector {
}
addNamed(importName, importedSourceIn, opts) {
(0, _assert.default)(typeof importName === "string");
_assert(typeof importName === "string");
return this._generateImport(this._applyDefaults(importedSourceIn, opts), importName);
}
......@@ -62,7 +58,8 @@ class ImportInjector {
});
optsList.push(opts);
} else {
(0, _assert.default)(!opts, "Unexpected secondary arguments.");
_assert(!opts, "Unexpected secondary arguments.");
optsList.push(importedSource);
}
......@@ -95,12 +92,18 @@ class ImportInjector {
ensureLiveReference,
ensureNoContext,
nameHint,
importPosition,
blockHoist
} = opts;
let name = nameHint || importName;
const isMod = (0, _isModule.default)(this._programPath);
const isModuleForNode = isMod && importingInterop === "node";
const isModuleForBabel = isMod && importingInterop === "babel";
if (importPosition === "after" && !isMod) {
throw new Error(`"importPosition": "after" is only supported in modules`);
}
const builder = new _importBuilder.default(importedSource, this._programScope, this._hub);
if (importedType === "es6") {
......@@ -240,7 +243,7 @@ class ImportInjector {
resultName
} = builder.done();
this._insertStatements(statements, blockHoist);
this._insertStatements(statements, importPosition, blockHoist);
if ((isDefault || isNamed) && ensureNoContext && resultName.type !== "Identifier") {
return t.sequenceExpression([t.numericLiteral(0), resultName]);
......@@ -249,21 +252,32 @@ class ImportInjector {
return resultName;
}
_insertStatements(statements, blockHoist = 3) {
statements.forEach(node => {
node._blockHoist = blockHoist;
});
_insertStatements(statements, importPosition = "before", blockHoist = 3) {
const body = this._programPath.get("body");
const targetPath = this._programPath.get("body").find(p => {
const val = p.node._blockHoist;
return Number.isFinite(val) && val < 4;
});
if (targetPath) {
targetPath.insertBefore(statements);
if (importPosition === "after") {
for (let i = body.length - 1; i >= 0; i--) {
if (body[i].isImportDeclaration()) {
body[i].insertAfter(statements);
return;
}
}
} else {
this._programPath.unshiftContainer("body", statements);
statements.forEach(node => {
node._blockHoist = blockHoist;
});
const targetPath = body.find(p => {
const val = p.node._blockHoist;
return Number.isFinite(val) && val < 4;
});
if (targetPath) {
targetPath.insertBefore(statements);
return;
}
}
this._programPath.unshiftContainer("body", statements);
}
}
......
......@@ -20,11 +20,9 @@ Object.defineProperty(exports, "isModule", {
}
});
var _importInjector = _interopRequireDefault(require("./import-injector"));
var _importInjector = require("./import-injector");
var _isModule = _interopRequireDefault(require("./is-module"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _isModule = require("./is-module");
function addDefault(path, importedSource, opts) {
return new _importInjector.default(path).addDefault(importedSource, opts);
......
{
"_from": "@babel/helper-module-imports@^7.0.0",
"_id": "@babel/helper-module-imports@7.7.0",
"_inBundle": false,
"_integrity": "sha512-Dv3hLKIC1jyfTkClvyEkYP2OlkzNvWs5+Q8WgPbxM5LMeorons7iPP91JM+DU7tRbhqA1ZeooPaMFvQrn23RHw==",
"_location": "/@babel/helper-module-imports",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@babel/helper-module-imports@^7.0.0",
"name": "@babel/helper-module-imports",
"escapedName": "@babel%2fhelper-module-imports",
"scope": "@babel",
"rawSpec": "^7.0.0",
"saveSpec": null,
"fetchSpec": "^7.0.0"
},
"_requiredBy": [
"/@babel/helper-module-transforms",
"/@babel/plugin-transform-async-to-generator",
"/@babel/plugin-transform-runtime",
"/@babel/preset-env",
"/@vue/babel-plugin-transform-vue-jsx",
"/@vue/babel-preset-app"
],
"_resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.7.0.tgz",
"_shasum": "99c095889466e5f7b6d66d98dffc58baaf42654d",
"_spec": "@babel/helper-module-imports@^7.0.0",
"_where": "C:\\Work\\OneDrive - bwstaff\\M4_Lab\\TV3\\NewVersion01\\LAFJLBmf939XYm5gj\\dev\\node_modules\\@vue\\babel-preset-app",
"author": {
"name": "Logan Smyth",
"email": "loganfsmyth@gmail.com"
},
"bundleDependencies": false,
"dependencies": {
"@babel/types": "^7.7.0"
},
"deprecated": false,
"name": "@babel/helper-module-imports",
"version": "7.14.5",
"description": "Babel helper functions for inserting module loads",
"devDependencies": {
"@babel/core": "^7.7.0"
},
"gitHead": "97faa83953cb87e332554fa559a4956d202343ea",
"homepage": "https://babeljs.io/",
"author": "The Babel Team (https://babel.dev/team)",
"homepage": "https://babel.dev/docs/en/next/babel-helper-module-imports",
"license": "MIT",
"main": "lib/index.js",
"name": "@babel/helper-module-imports",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-helper-module-imports"
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-helper-module-imports"
},
"main": "./lib/index.js",
"dependencies": {
"@babel/types": "^7.14.5"
},
"devDependencies": {
"@babel/core": "7.14.5",
"@babel/traverse": "7.14.5"
},
"version": "7.7.0"
}
"engines": {
"node": ">=6.9.0"
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
> Babel helper functions for implementing ES6 module transformations
See our website [@babel/helper-module-transforms](https://babeljs.io/docs/en/next/babel-helper-module-transforms.html) for more information.
See our website [@babel/helper-module-transforms](https://babeljs.io/docs/en/babel-helper-module-transforms) for more information.
## Install
......
......@@ -13,6 +13,12 @@ Object.defineProperty(exports, "isModule", {
return _helperModuleImports.isModule;
}
});
Object.defineProperty(exports, "rewriteThis", {
enumerable: true,
get: function () {
return _rewriteThis.default;
}
});
Object.defineProperty(exports, "hasExports", {
enumerable: true,
get: function () {
......@@ -25,44 +31,50 @@ Object.defineProperty(exports, "isSideEffectImport", {
return _normalizeAndLoadMetadata.isSideEffectImport;
}
});
Object.defineProperty(exports, "getModuleName", {
enumerable: true,
get: function () {
return _getModuleName.default;
}
});
var _assert = _interopRequireDefault(require("assert"));
var t = _interopRequireWildcard(require("@babel/types"));
var _assert = require("assert");
var _template = _interopRequireDefault(require("@babel/template"));
var t = require("@babel/types");
var _chunk = _interopRequireDefault(require("lodash/chunk"));
var _template = require("@babel/template");
var _helperModuleImports = require("@babel/helper-module-imports");
var _rewriteThis = _interopRequireDefault(require("./rewrite-this"));
var _rewriteLiveReferences = _interopRequireDefault(require("./rewrite-live-references"));
var _rewriteThis = require("./rewrite-this");
var _normalizeAndLoadMetadata = _interopRequireWildcard(require("./normalize-and-load-metadata"));
var _rewriteLiveReferences = require("./rewrite-live-references");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
var _normalizeAndLoadMetadata = require("./normalize-and-load-metadata");
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _getModuleName = require("./get-module-name");
function rewriteModuleStatementsAndPrepareHeader(path, {
loose,
exportName,
strict,
allowTopLevelThis,
strictMode,
loose,
noInterop,
importInterop = noInterop ? "none" : "babel",
lazy,
esNamespaceOnly
esNamespaceOnly,
constantReexports = loose,
enumerableModuleMeta = loose
}) {
(0, _assert.default)((0, _helperModuleImports.isModule)(path), "Cannot process module statements in a script");
(0, _normalizeAndLoadMetadata.validateImportInteropOption)(importInterop);
_assert((0, _helperModuleImports.isModule)(path), "Cannot process module statements in a script");
path.node.sourceType = "script";
const meta = (0, _normalizeAndLoadMetadata.default)(path, exportName, {
noInterop,
loose,
importInterop,
initializeReexports: constantReexports,
lazy,
esNamespaceOnly
});
......@@ -86,7 +98,7 @@ function rewriteModuleStatementsAndPrepareHeader(path, {
const headers = [];
if ((0, _normalizeAndLoadMetadata.hasExports)(meta) && !strict) {
headers.push(buildESModuleHeader(meta, loose));
headers.push(buildESModuleHeader(meta, enumerableModuleMeta));
}
const nameList = buildExportNameListDeclaration(path, meta);
......@@ -96,7 +108,7 @@ function rewriteModuleStatementsAndPrepareHeader(path, {
headers.push(nameList.statement);
}
headers.push(...buildExportInitializationStatements(path, meta, loose));
headers.push(...buildExportInitializationStatements(path, meta, constantReexports));
return {
meta,
headers
......@@ -114,6 +126,12 @@ function wrapInterop(programPath, expr, type) {
return null;
}
if (type === "node-namespace") {
return t.callExpression(programPath.hub.addHelper("interopRequireWildcard"), [expr, t.booleanLiteral(true)]);
} else if (type === "node-default") {
return null;
}
let helper;
if (type === "default") {
......@@ -127,7 +145,7 @@ function wrapInterop(programPath, expr, type) {
return t.callExpression(programPath.hub.addHelper(helper), [expr]);
}
function buildNamespaceInitStatements(metadata, sourceMetadata, loose = false) {
function buildNamespaceInitStatements(metadata, sourceMetadata, constantReexports = false) {
const statements = [];
let srcNamespace = t.identifier(sourceMetadata.name);
if (sourceMetadata.lazy) srcNamespace = t.callExpression(srcNamespace, []);
......@@ -140,8 +158,8 @@ function buildNamespaceInitStatements(metadata, sourceMetadata, loose = false) {
}));
}
if (loose) {
statements.push(...buildReexportsFromMeta(metadata, sourceMetadata, loose));
if (constantReexports) {
statements.push(...buildReexportsFromMeta(metadata, sourceMetadata, true));
}
for (const exportName of sourceMetadata.reexportNamespace) {
......@@ -160,7 +178,7 @@ function buildNamespaceInitStatements(metadata, sourceMetadata, loose = false) {
}
if (sourceMetadata.reexportAll) {
const statement = buildNamespaceReexport(metadata, t.cloneNode(srcNamespace), loose);
const statement = buildNamespaceReexport(metadata, t.cloneNode(srcNamespace), constantReexports);
statement.loc = sourceMetadata.reexportAll.loc;
statements.push(statement);
}
......@@ -168,30 +186,53 @@ function buildNamespaceInitStatements(metadata, sourceMetadata, loose = false) {
return statements;
}
const getTemplateForReexport = loose => {
return loose ? _template.default.statement`EXPORTS.EXPORT_NAME = NAMESPACE.IMPORT_NAME;` : _template.default`
Object.defineProperty(EXPORTS, "EXPORT_NAME", {
enumerable: true,
get: function() {
return NAMESPACE.IMPORT_NAME;
},
});
`;
const ReexportTemplate = {
constant: _template.default.statement`EXPORTS.EXPORT_NAME = NAMESPACE_IMPORT;`,
constantComputed: _template.default.statement`EXPORTS["EXPORT_NAME"] = NAMESPACE_IMPORT;`,
spec: (0, _template.default)`
Object.defineProperty(EXPORTS, "EXPORT_NAME", {
enumerable: true,
get: function() {
return NAMESPACE_IMPORT;
},
});
`
};
const buildReexportsFromMeta = (meta, metadata, loose) => {
const buildReexportsFromMeta = (meta, metadata, constantReexports) => {
const namespace = metadata.lazy ? t.callExpression(t.identifier(metadata.name), []) : t.identifier(metadata.name);
const templateForCurrentMode = getTemplateForReexport(loose);
return Array.from(metadata.reexports, ([exportName, importName]) => templateForCurrentMode({
EXPORTS: meta.exportName,
EXPORT_NAME: exportName,
NAMESPACE: t.cloneNode(namespace),
IMPORT_NAME: importName
}));
const {
stringSpecifiers
} = meta;
return Array.from(metadata.reexports, ([exportName, importName]) => {
let NAMESPACE_IMPORT = t.cloneNode(namespace);
if (importName === "default" && metadata.interop === "node-default") {} else if (stringSpecifiers.has(importName)) {
NAMESPACE_IMPORT = t.memberExpression(NAMESPACE_IMPORT, t.stringLiteral(importName), true);
} else {
NAMESPACE_IMPORT = t.memberExpression(NAMESPACE_IMPORT, t.identifier(importName));
}
const astNodes = {
EXPORTS: meta.exportName,
EXPORT_NAME: exportName,
NAMESPACE_IMPORT
};
if (constantReexports || t.isIdentifier(NAMESPACE_IMPORT)) {
if (stringSpecifiers.has(exportName)) {
return ReexportTemplate.constantComputed(astNodes);
} else {
return ReexportTemplate.constant(astNodes);
}
} else {
return ReexportTemplate.spec(astNodes);
}
});
};
function buildESModuleHeader(metadata, enumerable = false) {
return (enumerable ? _template.default.statement`
function buildESModuleHeader(metadata, enumerableModuleMeta = false) {
return (enumerableModuleMeta ? _template.default.statement`
EXPORTS.__esModule = true;
` : _template.default.statement`
Object.defineProperty(EXPORTS, "__esModule", {
......@@ -202,11 +243,12 @@ function buildESModuleHeader(metadata, enumerable = false) {
});
}
function buildNamespaceReexport(metadata, namespace, loose) {
return (loose ? _template.default.statement`
function buildNamespaceReexport(metadata, namespace, constantReexports) {
return (constantReexports ? _template.default.statement`
Object.keys(NAMESPACE).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
VERIFY_NAME_LIST;
if (key in EXPORTS && EXPORTS[key] === NAMESPACE[key]) return;
EXPORTS[key] = NAMESPACE[key];
});
......@@ -214,6 +256,7 @@ function buildNamespaceReexport(metadata, namespace, loose) {
Object.keys(NAMESPACE).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
VERIFY_NAME_LIST;
if (key in EXPORTS && EXPORTS[key] === NAMESPACE[key]) return;
Object.defineProperty(EXPORTS, key, {
enumerable: true,
......@@ -225,7 +268,7 @@ function buildNamespaceReexport(metadata, namespace, loose) {
`)({
NAMESPACE: namespace,
EXPORTS: metadata.exportName,
VERIFY_NAME_LIST: metadata.exportNameListName ? _template.default`
VERIFY_NAME_LIST: metadata.exportNameListName ? (0, _template.default)`
if (Object.prototype.hasOwnProperty.call(EXPORTS_LIST, key)) return;
`({
EXPORTS_LIST: metadata.exportNameListName
......@@ -253,7 +296,7 @@ function buildExportNameListDeclaration(programPath, metadata) {
exportedVars[exportName] = true;
}
hasReexport = hasReexport || data.reexportAll;
hasReexport = hasReexport || !!data.reexportAll;
}
if (!hasReexport || Object.keys(exportedVars).length === 0) return null;
......@@ -265,7 +308,7 @@ function buildExportNameListDeclaration(programPath, metadata) {
};
}
function buildExportInitializationStatements(programPath, metadata, loose = false) {
function buildExportInitializationStatements(programPath, metadata, constantReexports = false) {
const initStatements = [];
const exportNames = [];
......@@ -278,8 +321,8 @@ function buildExportInitializationStatements(programPath, metadata, loose = fals
}
for (const data of metadata.source.values()) {
if (!loose) {
initStatements.push(...buildReexportsFromMeta(metadata, data, loose));
if (!constantReexports) {
initStatements.push(...buildReexportsFromMeta(metadata, data, false));
}
for (const exportName of data.reexportNamespace) {
......@@ -287,16 +330,43 @@ function buildExportInitializationStatements(programPath, metadata, loose = fals
}
}
initStatements.push(...(0, _chunk.default)(exportNames, 100).map(members => {
initStatements.push(...chunk(exportNames, 100).map(members => {
return buildInitStatement(metadata, members, programPath.scope.buildUndefinedNode());
}));
return initStatements;
}
const InitTemplate = {
computed: _template.default.expression`EXPORTS["NAME"] = VALUE`,
default: _template.default.expression`EXPORTS.NAME = VALUE`
};
function buildInitStatement(metadata, exportNames, initExpr) {
return t.expressionStatement(exportNames.reduce((acc, exportName) => _template.default.expression`EXPORTS.NAME = VALUE`({
EXPORTS: metadata.exportName,
NAME: exportName,
VALUE: acc
}), initExpr));
const {
stringSpecifiers,
exportName: EXPORTS
} = metadata;
return t.expressionStatement(exportNames.reduce((acc, exportName) => {
const params = {
EXPORTS,
NAME: exportName,
VALUE: acc
};
if (stringSpecifiers.has(exportName)) {
return InitTemplate.computed(params);
} else {
return InitTemplate.default(params);
}
}, initExpr));
}
function chunk(array, size) {
const chunks = [];
for (let i = 0; i < array.length; i += size) {
chunks.push(array.slice(i, i + size));
}
return chunks;
}
\ No newline at end of file
......@@ -5,13 +5,14 @@ Object.defineProperty(exports, "__esModule", {
});
exports.hasExports = hasExports;
exports.isSideEffectImport = isSideEffectImport;
exports.validateImportInteropOption = validateImportInteropOption;
exports.default = normalizeModuleAndLoadMetadata;
var _path = require("path");
var _helperSplitExportDeclaration = _interopRequireDefault(require("@babel/helper-split-export-declaration"));
var _helperValidatorIdentifier = require("@babel/helper-validator-identifier");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
function hasExports(metadata) {
return metadata.hasExports;
......@@ -21,25 +22,42 @@ function isSideEffectImport(source) {
return source.imports.size === 0 && source.importsNamespace.size === 0 && source.reexports.size === 0 && source.reexportNamespace.size === 0 && !source.reexportAll;
}
function validateImportInteropOption(importInterop) {
if (typeof importInterop !== "function" && importInterop !== "none" && importInterop !== "babel" && importInterop !== "node") {
throw new Error(`.importInterop must be one of "none", "babel", "node", or a function returning one of those values (received ${importInterop}).`);
}
return importInterop;
}
function resolveImportInterop(importInterop, source) {
if (typeof importInterop === "function") {
return validateImportInteropOption(importInterop(source));
}
return importInterop;
}
function normalizeModuleAndLoadMetadata(programPath, exportName, {
noInterop = false,
loose = false,
importInterop,
initializeReexports = false,
lazy = false,
esNamespaceOnly = false
} = {}) {
}) {
if (!exportName) {
exportName = programPath.scope.generateUidIdentifier("exports").name;
}
const stringSpecifiers = new Set();
nameAnonymousExports(programPath);
const {
local,
source,
hasExports
} = getModuleMetadata(programPath, {
loose,
initializeReexports,
lazy
});
}, stringSpecifiers);
removeModuleDeclarations(programPath);
for (const [, metadata] of source) {
......@@ -47,10 +65,16 @@ function normalizeModuleAndLoadMetadata(programPath, exportName, {
metadata.name = metadata.importsNamespace.values().next().value;
}
if (noInterop) metadata.interop = "none";else if (esNamespaceOnly) {
if (metadata.interop === "namespace") {
metadata.interop = "default";
}
const resolvedInterop = resolveImportInterop(importInterop, metadata.source);
if (resolvedInterop === "none") {
metadata.interop = "none";
} else if (resolvedInterop === "node" && metadata.interop === "namespace") {
metadata.interop = "node-namespace";
} else if (resolvedInterop === "node" && metadata.interop === "default") {
metadata.interop = "node-default";
} else if (esNamespaceOnly && metadata.interop === "namespace") {
metadata.interop = "default";
}
}
......@@ -59,15 +83,42 @@ function normalizeModuleAndLoadMetadata(programPath, exportName, {
exportNameListName: null,
hasExports,
local,
source
source,
stringSpecifiers
};
}
function getExportSpecifierName(path, stringSpecifiers) {
if (path.isIdentifier()) {
return path.node.name;
} else if (path.isStringLiteral()) {
const stringValue = path.node.value;
if (!(0, _helperValidatorIdentifier.isIdentifierName)(stringValue)) {
stringSpecifiers.add(stringValue);
}
return stringValue;
} else {
throw new Error(`Expected export specifier to be either Identifier or StringLiteral, got ${path.node.type}`);
}
}
function assertExportSpecifier(path) {
if (path.isExportSpecifier()) {
return;
} else if (path.isExportNamespaceSpecifier()) {
throw path.buildCodeFrameError("Export namespace should be first transformed by `@babel/plugin-proposal-export-namespace-from`.");
} else {
throw path.buildCodeFrameError("Unexpected export specifier type");
}
}
function getModuleMetadata(programPath, {
loose,
lazy
}) {
const localData = getLocalExportMetadata(programPath, loose);
lazy,
initializeReexports
}, stringSpecifiers) {
const localData = getLocalExportMetadata(programPath, initializeReexports, stringSpecifiers);
const sourceData = new Map();
const getData = sourceNode => {
......@@ -84,7 +135,8 @@ function getModuleMetadata(programPath, {
reexports: new Map(),
reexportNamespace: new Set(),
reexportAll: null,
lazy: false
lazy: false,
source
};
sourceData.set(source, data);
}
......@@ -121,7 +173,7 @@ function getModuleMetadata(programPath, {
});
}
} else if (spec.isImportSpecifier()) {
const importName = spec.get("imported").node.name;
const importName = getExportSpecifierName(spec.get("imported"), stringSpecifiers);
const localName = spec.get("local").node.name;
data.imports.set(localName, importName);
const reexport = localData.get(localName);
......@@ -146,16 +198,13 @@ function getModuleMetadata(programPath, {
const data = getData(child.node.source);
if (!data.loc) data.loc = child.node.loc;
child.get("specifiers").forEach(spec => {
if (!spec.isExportSpecifier()) {
throw spec.buildCodeFrameError("Unexpected export specifier type");
}
const importName = spec.get("local").node.name;
const exportName = spec.get("exported").node.name;
assertExportSpecifier(spec);
const importName = getExportSpecifierName(spec.get("local"), stringSpecifiers);
const exportName = getExportSpecifierName(spec.get("exported"), stringSpecifiers);
data.reexports.set(exportName, importName);
if (exportName === "__esModule") {
throw exportName.buildCodeFrameError('Illegal export "__esModule".');
throw spec.get("exported").buildCodeFrameError('Illegal export "__esModule".');
}
});
} else if (child.isExportNamedDeclaration() || child.isExportDefaultDeclaration()) {
......@@ -212,7 +261,7 @@ function getModuleMetadata(programPath, {
};
}
function getLocalExportMetadata(programPath, loose) {
function getLocalExportMetadata(programPath, initializeReexports, stringSpecifiers) {
const bindingKindLookup = new Map();
programPath.get("body").forEach(child => {
let kind;
......@@ -225,9 +274,10 @@ function getLocalExportMetadata(programPath, loose) {
if (child.isExportNamedDeclaration()) {
if (child.node.declaration) {
child = child.get("declaration");
} else if (loose && child.node.source && child.get("source").isStringLiteral()) {
child.node.specifiers.forEach(specifier => {
bindingKindLookup.set(specifier.local.name, "block");
} else if (initializeReexports && child.node.source && child.get("source").isStringLiteral()) {
child.get("specifiers").forEach(spec => {
assertExportSpecifier(spec);
bindingKindLookup.set(spec.get("local").node.name, "block");
});
return;
}
......@@ -276,7 +326,7 @@ function getLocalExportMetadata(programPath, loose) {
};
programPath.get("body").forEach(child => {
if (child.isExportNamedDeclaration() && (loose || !child.node.source)) {
if (child.isExportNamedDeclaration() && (initializeReexports || !child.node.source)) {
if (child.node.declaration) {
const declaration = child.get("declaration");
const ids = declaration.getOuterBindingIdentifierPaths();
......@@ -291,12 +341,14 @@ function getLocalExportMetadata(programPath, loose) {
child.get("specifiers").forEach(spec => {
const local = spec.get("local");
const exported = spec.get("exported");
const localMetadata = getLocalMetadata(local);
const exportName = getExportSpecifierName(exported, stringSpecifiers);
if (exported.node.name === "__esModule") {
if (exportName === "__esModule") {
throw exported.buildCodeFrameError('Illegal export "__esModule".');
}
getLocalMetadata(local).names.push(exported.node.name);
localMetadata.names.push(exportName);
});
}
} else if (child.isExportDefaultDeclaration()) {
......
......@@ -5,19 +5,13 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = rewriteLiveReferences;
var _assert = _interopRequireDefault(require("assert"));
var _assert = require("assert");
var t = _interopRequireWildcard(require("@babel/types"));
var t = require("@babel/types");
var _template = _interopRequireDefault(require("@babel/template"));
var _template = require("@babel/template");
var _helperSimpleAccess = _interopRequireDefault(require("@babel/helper-simple-access"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _helperSimpleAccess = require("@babel/helper-simple-access");
function rewriteLiveReferences(programPath, metadata) {
const imported = new Map();
......@@ -48,14 +42,15 @@ function rewriteLiveReferences(programPath, metadata) {
exportMeta.push(...data.names);
}
programPath.traverse(rewriteBindingInitVisitor, {
const rewriteBindingInitVisitorState = {
metadata,
requeueInParent,
scope: programPath.scope,
exported
});
};
programPath.traverse(rewriteBindingInitVisitor, rewriteBindingInitVisitorState);
(0, _helperSimpleAccess.default)(programPath, new Set([...Array.from(imported.keys()), ...Array.from(exported.keys())]));
programPath.traverse(rewriteReferencesVisitor, {
const rewriteReferencesVisitorState = {
seen: new WeakSet(),
metadata,
requeueInParent,
......@@ -72,17 +67,20 @@ function rewriteLiveReferences(programPath, metadata) {
let namespace = t.identifier(meta.name);
if (meta.lazy) namespace = t.callExpression(namespace, []);
return t.memberExpression(namespace, t.identifier(importName));
if (importName === "default" && meta.interop === "node-default") {
return namespace;
}
const computed = metadata.stringSpecifiers.has(importName);
return t.memberExpression(namespace, computed ? t.stringLiteral(importName) : t.identifier(importName), computed);
}
});
};
programPath.traverse(rewriteReferencesVisitor, rewriteReferencesVisitorState);
}
const rewriteBindingInitVisitor = {
ClassProperty(path) {
path.skip();
},
Function(path) {
Scope(path) {
path.skip();
},
......@@ -127,7 +125,11 @@ const rewriteBindingInitVisitor = {
const buildBindingExportAssignmentExpression = (metadata, exportNames, localExpr) => {
return (exportNames || []).reduce((expr, exportName) => {
return t.assignmentExpression("=", t.memberExpression(t.identifier(metadata.exportName), t.identifier(exportName)), expr);
const {
stringSpecifiers
} = metadata;
const computed = stringSpecifiers.has(exportName);
return t.assignmentExpression("=", t.memberExpression(t.identifier(metadata.exportName), computed ? t.stringLiteral(exportName) : t.identifier(exportName), computed), expr);
}, localExpr);
};
......@@ -151,25 +153,29 @@ const rewriteReferencesVisitor = {
if (seen.has(path.node)) return;
seen.add(path.node);
const localName = path.node.name;
const localBinding = path.scope.getBinding(localName);
const rootBinding = scope.getBinding(localName);
if (rootBinding !== localBinding) return;
const importData = imported.get(localName);
if (importData) {
const localBinding = path.scope.getBinding(localName);
const rootBinding = scope.getBinding(localName);
if (rootBinding !== localBinding) return;
const ref = buildImportReference(importData, path.node);
ref.loc = path.node.loc;
if (path.parentPath.isCallExpression({
if ((path.parentPath.isCallExpression({
callee: path.node
}) || path.parentPath.isOptionalCallExpression({
callee: path.node
}) && t.isMemberExpression(ref)) {
}) || path.parentPath.isTaggedTemplateExpression({
tag: path.node
})) && t.isMemberExpression(ref)) {
path.replaceWith(t.sequenceExpression([t.numericLiteral(0), ref]));
} else if (path.isJSXIdentifier() && t.isMemberExpression(ref)) {
const {
object,
property
} = ref;
path.replaceWith(t.JSXMemberExpression(t.JSXIdentifier(object.name), t.JSXIdentifier(property.name)));
path.replaceWith(t.jsxMemberExpression(t.jsxIdentifier(object.name), t.jsxIdentifier(property.name)));
} else {
path.replaceWith(ref);
}
......@@ -204,8 +210,9 @@ const rewriteReferencesVisitor = {
const exportedNames = exported.get(localName);
const importData = imported.get(localName);
if ((exportedNames === null || exportedNames === void 0 ? void 0 : exportedNames.length) > 0 || importData) {
(0, _assert.default)(path.node.operator === "=", "Path was not simplified");
if ((exportedNames == null ? void 0 : exportedNames.length) > 0 || importData) {
_assert(path.node.operator === "=", "Path was not simplified");
const assignment = path.node;
if (importData) {
......@@ -248,5 +255,45 @@ const rewriteReferencesVisitor = {
}
}
},
"ForOfStatement|ForInStatement"(path) {
const {
scope,
node
} = path;
const {
left
} = node;
const {
exported,
scope: programScope
} = this;
if (!t.isVariableDeclaration(left)) {
let didTransform = false;
const bodyPath = path.get("body");
const loopBodyScope = bodyPath.scope;
for (const name of Object.keys(t.getOuterBindingIdentifiers(left))) {
if (exported.get(name) && programScope.getBinding(name) === scope.getBinding(name)) {
didTransform = true;
if (loopBodyScope.hasOwnBinding(name)) {
loopBodyScope.rename(name);
}
}
}
if (!didTransform) {
return;
}
const newLoopId = scope.generateUidIdentifierBasedOnNode(left);
bodyPath.unshiftContainer("body", t.expressionStatement(t.assignmentExpression("=", left, newLoopId)));
path.get("left").replaceWith(t.variableDeclaration("let", [t.variableDeclarator(t.cloneNode(newLoopId))]));
scope.registerDeclaration(path.get("left"));
}
}
};
\ No newline at end of file
......@@ -5,25 +5,21 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = rewriteThis;
function rewriteThis(programPath) {
programPath.traverse(rewriteThisVisitor);
}
var _helperReplaceSupers = require("@babel/helper-replace-supers");
const rewriteThisVisitor = {
ThisExpression(path) {
path.replaceWith(path.scope.buildUndefinedNode());
},
var _traverse = require("@babel/traverse");
Function(path) {
if (!path.isArrowFunctionExpression()) path.skip();
},
var t = require("@babel/types");
ClassProperty(path) {
path.skip();
},
function rewriteThis(programPath) {
(0, _traverse.default)(programPath.node, Object.assign({}, rewriteThisVisitor, {
noScope: true
}));
}
ClassPrivateProperty(path) {
path.skip();
const rewriteThisVisitor = _traverse.default.visitors.merge([_helperReplaceSupers.environmentVisitor, {
ThisExpression(path) {
path.replaceWith(t.unaryExpression("void", t.numericLiteral(0), true));
}
};
\ No newline at end of file
}]);
\ No newline at end of file
{
"_from": "@babel/helper-module-transforms@^7.1.0",
"_id": "@babel/helper-module-transforms@7.7.0",
"_inBundle": false,
"_integrity": "sha512-rXEefBuheUYQyX4WjV19tuknrJFwyKw0HgzRwbkyTbB+Dshlq7eqkWbyjzToLrMZk/5wKVKdWFluiAsVkHXvuQ==",
"_location": "/@babel/helper-module-transforms",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@babel/helper-module-transforms@^7.1.0",
"name": "@babel/helper-module-transforms",
"escapedName": "@babel%2fhelper-module-transforms",
"scope": "@babel",
"rawSpec": "^7.1.0",
"saveSpec": null,
"fetchSpec": "^7.1.0"
},
"_requiredBy": [
"/@babel/plugin-transform-modules-amd",
"/@babel/plugin-transform-modules-commonjs",
"/@babel/plugin-transform-modules-umd"
],
"_resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.7.0.tgz",
"_shasum": "154a69f0c5b8fd4d39e49750ff7ac4faa3f36786",
"_spec": "@babel/helper-module-transforms@^7.1.0",
"_where": "C:\\Work\\OneDrive - bwstaff\\M4_Lab\\TV3\\NewVersion01\\LAFJLBmf939XYm5gj\\dev\\node_modules\\@babel\\plugin-transform-modules-amd",
"author": {
"name": "Logan Smyth",
"email": "loganfsmyth@gmail.com"
},
"bundleDependencies": false,
"dependencies": {
"@babel/helper-module-imports": "^7.7.0",
"@babel/helper-simple-access": "^7.7.0",
"@babel/helper-split-export-declaration": "^7.7.0",
"@babel/template": "^7.7.0",
"@babel/types": "^7.7.0",
"lodash": "^4.17.13"
},
"deprecated": false,
"name": "@babel/helper-module-transforms",
"version": "7.14.5",
"description": "Babel helper functions for implementing ES6 module transformations",
"gitHead": "97faa83953cb87e332554fa559a4956d202343ea",
"homepage": "https://babeljs.io/",
"author": "The Babel Team (https://babel.dev/team)",
"homepage": "https://babel.dev/docs/en/next/babel-helper-module-transforms",
"license": "MIT",
"main": "lib/index.js",
"name": "@babel/helper-module-transforms",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-helper-module-transforms"
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-helper-module-transforms"
},
"main": "./lib/index.js",
"dependencies": {
"@babel/helper-module-imports": "^7.14.5",
"@babel/helper-replace-supers": "^7.14.5",
"@babel/helper-simple-access": "^7.14.5",
"@babel/helper-split-export-declaration": "^7.14.5",
"@babel/helper-validator-identifier": "^7.14.5",
"@babel/template": "^7.14.5",
"@babel/traverse": "^7.14.5",
"@babel/types": "^7.14.5"
},
"version": "7.7.0"
}
"engines": {
"node": ">=6.9.0"
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
> Helper function to optimise call expression
See our website [@babel/helper-optimise-call-expression](https://babeljs.io/docs/en/next/babel-helper-optimise-call-expression.html) for more information.
See our website [@babel/helper-optimise-call-expression](https://babeljs.io/docs/en/babel-helper-optimise-call-expression) for more information.
## Install
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment