Commit 762b95bc authored by Cholgrrr's avatar Cholgrrr
Browse files

Merge branch 'New_Structure' of https://gitlab.com/Cholgrrr/m4labplatform into New_Structure

parents 613a2f33 a2e8cafb
...@@ -5,26 +5,22 @@ Object.defineProperty(exports, "__esModule", { ...@@ -5,26 +5,22 @@ Object.defineProperty(exports, "__esModule", {
}); });
exports.default = parseAndBuildMetadata; exports.default = parseAndBuildMetadata;
var t = _interopRequireWildcard(require("@babel/types")); var t = require("@babel/types");
var _parser = require("@babel/parser"); var _parser = require("@babel/parser");
var _codeFrame = require("@babel/code-frame"); var _codeFrame = require("@babel/code-frame");
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; }
const PATTERN = /^[_$A-Z0-9]+$/; const PATTERN = /^[_$A-Z0-9]+$/;
function parseAndBuildMetadata(formatter, code, opts) { function parseAndBuildMetadata(formatter, code, opts) {
const ast = parseWithCodeFrame(code, opts.parser);
const { const {
placeholderWhitelist, placeholderWhitelist,
placeholderPattern, placeholderPattern,
preserveComments, preserveComments,
syntacticPlaceholders syntacticPlaceholders
} = opts; } = opts;
const ast = parseWithCodeFrame(code, opts.parser, syntacticPlaceholders);
t.removePropertiesDeep(ast, { t.removePropertiesDeep(ast, {
preserveComments preserveComments
}); });
...@@ -54,6 +50,8 @@ function parseAndBuildMetadata(formatter, code, opts) { ...@@ -54,6 +50,8 @@ function parseAndBuildMetadata(formatter, code, opts) {
} }
function placeholderVisitorHandler(node, ancestors, state) { function placeholderVisitorHandler(node, ancestors, state) {
var _state$placeholderWhi;
let name; let name;
if (t.isPlaceholder(node)) { if (t.isPlaceholder(node)) {
...@@ -79,7 +77,7 @@ function placeholderVisitorHandler(node, ancestors, state) { ...@@ -79,7 +77,7 @@ function placeholderVisitorHandler(node, ancestors, state) {
throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'"); throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'");
} }
if (state.isLegacyRef.value && (state.placeholderPattern === false || !(state.placeholderPattern || PATTERN).test(name)) && (!state.placeholderWhitelist || !state.placeholderWhitelist.has(name))) { if (state.isLegacyRef.value && (state.placeholderPattern === false || !(state.placeholderPattern || PATTERN).test(name)) && !((_state$placeholderWhi = state.placeholderWhitelist) != null && _state$placeholderWhi.has(name))) {
return; return;
} }
...@@ -145,13 +143,19 @@ function resolveAncestors(ast, ancestors) { ...@@ -145,13 +143,19 @@ function resolveAncestors(ast, ancestors) {
}; };
} }
function parseWithCodeFrame(code, parserOpts) { function parseWithCodeFrame(code, parserOpts, syntacticPlaceholders) {
const plugins = (parserOpts.plugins || []).slice();
if (syntacticPlaceholders !== false) {
plugins.push("placeholders");
}
parserOpts = Object.assign({ parserOpts = Object.assign({
allowReturnOutsideFunction: true, allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true, allowSuperOutsideMethod: true,
sourceType: "module" sourceType: "module"
}, parserOpts, { }, parserOpts, {
plugins: (parserOpts.plugins || []).concat("placeholders") plugins
}); });
try { try {
......
...@@ -5,11 +5,7 @@ Object.defineProperty(exports, "__esModule", { ...@@ -5,11 +5,7 @@ Object.defineProperty(exports, "__esModule", {
}); });
exports.default = populatePlaceholders; exports.default = populatePlaceholders;
var t = _interopRequireWildcard(require("@babel/types")); var t = 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 populatePlaceholders(metadata, replacements) { function populatePlaceholders(metadata, replacements) {
const ast = t.cloneNode(metadata.ast); const ast = t.cloneNode(metadata.ast);
......
...@@ -7,11 +7,9 @@ exports.default = stringTemplate; ...@@ -7,11 +7,9 @@ exports.default = stringTemplate;
var _options = require("./options"); var _options = require("./options");
var _parse = _interopRequireDefault(require("./parse")); var _parse = require("./parse");
var _populate = _interopRequireDefault(require("./populate")); var _populate = require("./populate");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function stringTemplate(formatter, code, opts) { function stringTemplate(formatter, code, opts) {
code = formatter.code(code); code = formatter.code(code);
......
{ {
"_from": "@babel/template@^7.7.0", "name": "@babel/template",
"_id": "@babel/template@7.7.0", "version": "7.14.5",
"_inBundle": false,
"_integrity": "sha512-OKcwSYOW1mhWbnTBgQY5lvg1Fxg+VyfQGjcBduZFljfc044J5iDlnDSfhQ867O17XHiSCxYHUxHg2b7ryitbUQ==",
"_location": "/@babel/template",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@babel/template@^7.7.0",
"name": "@babel/template",
"escapedName": "@babel%2ftemplate",
"scope": "@babel",
"rawSpec": "^7.7.0",
"saveSpec": null,
"fetchSpec": "^7.7.0"
},
"_requiredBy": [
"/@babel/core",
"/@babel/helper-function-name",
"/@babel/helper-module-transforms",
"/@babel/helper-remap-async-to-generator",
"/@babel/helper-simple-access",
"/@babel/helper-wrap-function",
"/@babel/helpers"
],
"_resolved": "https://registry.npmjs.org/@babel/template/-/template-7.7.0.tgz",
"_shasum": "4fadc1b8e734d97f56de39c77de76f2562e597d0",
"_spec": "@babel/template@^7.7.0",
"_where": "C:\\Work\\OneDrive - bwstaff\\M4_Lab\\TV3\\NewVersion01\\LAFJLBmf939XYm5gj\\dev\\node_modules\\@babel\\core",
"author": {
"name": "Sebastian McKenzie",
"email": "sebmck@gmail.com"
},
"bundleDependencies": false,
"dependencies": {
"@babel/code-frame": "^7.0.0",
"@babel/parser": "^7.7.0",
"@babel/types": "^7.7.0"
},
"deprecated": false,
"description": "Generate an AST from a string template.", "description": "Generate an AST from a string template.",
"gitHead": "97faa83953cb87e332554fa559a4956d202343ea", "author": "The Babel Team (https://babel.dev/team)",
"homepage": "https://babeljs.io/", "homepage": "https://babel.dev/docs/en/next/babel-template",
"bugs": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20template%22+is%3Aopen",
"license": "MIT", "license": "MIT",
"main": "lib/index.js",
"name": "@babel/template",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-template" "url": "https://github.com/babel/babel.git",
"directory": "packages/babel-template"
},
"main": "./lib/index.js",
"dependencies": {
"@babel/code-frame": "^7.14.5",
"@babel/parser": "^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 @@ ...@@ -2,7 +2,7 @@
> The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes > The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes
See our website [@babel/traverse](https://babeljs.io/docs/en/next/babel-traverse.html) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20traverse%22+is%3Aopen) associated with this package. See our website [@babel/traverse](https://babeljs.io/docs/en/babel-traverse) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20traverse%22+is%3Aopen) associated with this package.
## Install ## Install
......
...@@ -5,21 +5,16 @@ Object.defineProperty(exports, "__esModule", { ...@@ -5,21 +5,16 @@ Object.defineProperty(exports, "__esModule", {
}); });
exports.default = void 0; exports.default = void 0;
var _path = _interopRequireDefault(require("./path")); var _path = require("./path");
var t = _interopRequireWildcard(require("@babel/types")); var t = 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 }; }
const testing = process.env.NODE_ENV === "test"; const testing = process.env.NODE_ENV === "test";
class TraversalContext { class TraversalContext {
constructor(scope, opts, state, parentPath) { constructor(scope, opts, state, parentPath) {
this.queue = null; this.queue = null;
this.priorityQueue = null;
this.parentPath = parentPath; this.parentPath = parentPath;
this.scope = scope; this.scope = scope;
this.state = state; this.state = state;
...@@ -31,7 +26,7 @@ class TraversalContext { ...@@ -31,7 +26,7 @@ class TraversalContext {
if (opts.enter || opts.exit) return true; if (opts.enter || opts.exit) return true;
if (opts[node.type]) return true; if (opts[node.type]) return true;
const keys = t.VISITOR_KEYS[node.type]; const keys = t.VISITOR_KEYS[node.type];
if (!keys || !keys.length) return false; if (!(keys != null && keys.length)) return false;
for (const key of keys) { for (const key of keys) {
if (node[key]) return true; if (node[key]) return true;
...@@ -90,7 +85,7 @@ class TraversalContext { ...@@ -90,7 +85,7 @@ class TraversalContext {
visitQueue(queue) { visitQueue(queue) {
this.queue = queue; this.queue = queue;
this.priorityQueue = []; this.priorityQueue = [];
const visited = []; const visited = new WeakSet();
let stop = false; let stop = false;
for (const path of queue) { for (const path of queue) {
...@@ -106,8 +101,11 @@ class TraversalContext { ...@@ -106,8 +101,11 @@ class TraversalContext {
this.trap = true; this.trap = true;
} }
if (visited.indexOf(path.node) >= 0) continue; const {
visited.push(path.node); node
} = path;
if (visited.has(node)) continue;
if (node) visited.add(node);
if (path.visit()) { if (path.visit()) {
stop = true; stop = true;
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
exports.default = traverse;
Object.defineProperty(exports, "NodePath", { Object.defineProperty(exports, "NodePath", {
enumerable: true, enumerable: true,
get: function () { get: function () {
...@@ -22,35 +21,26 @@ Object.defineProperty(exports, "Hub", { ...@@ -22,35 +21,26 @@ Object.defineProperty(exports, "Hub", {
return _hub.default; return _hub.default;
} }
}); });
exports.visitors = void 0; exports.visitors = exports.default = void 0;
var _context = _interopRequireDefault(require("./context")); var _context = require("./context");
var visitors = _interopRequireWildcard(require("./visitors")); var visitors = require("./visitors");
exports.visitors = visitors; exports.visitors = visitors;
var _includes = _interopRequireDefault(require("lodash/includes")); var t = require("@babel/types");
var t = _interopRequireWildcard(require("@babel/types")); var cache = require("./cache");
var cache = _interopRequireWildcard(require("./cache")); var _path = require("./path");
var _path = _interopRequireDefault(require("./path")); var _scope = require("./scope");
var _scope = _interopRequireDefault(require("./scope")); var _hub = require("./hub");
var _hub = _interopRequireDefault(require("./hub")); function traverse(parent, opts = {}, scope, state, parentPath) {
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 }; }
function traverse(parent, opts, scope, state, parentPath) {
if (!parent) return; if (!parent) return;
if (!opts) opts = {};
if (!opts.noScope && !scope) { if (!opts.noScope && !scope) {
if (parent.type !== "Program" && parent.type !== "File") { if (parent.type !== "Program" && parent.type !== "File") {
...@@ -66,6 +56,8 @@ function traverse(parent, opts, scope, state, parentPath) { ...@@ -66,6 +56,8 @@ function traverse(parent, opts, scope, state, parentPath) {
traverse.node(parent, opts, scope, state, parentPath); traverse.node(parent, opts, scope, state, parentPath);
} }
var _default = traverse;
exports.default = _default;
traverse.visitors = visitors; traverse.visitors = visitors;
traverse.verify = visitors.verify; traverse.verify = visitors.verify;
traverse.explode = visitors.explode; traverse.explode = visitors.explode;
...@@ -95,15 +87,15 @@ traverse.removeProperties = function (tree, opts) { ...@@ -95,15 +87,15 @@ traverse.removeProperties = function (tree, opts) {
return tree; return tree;
}; };
function hasBlacklistedType(path, state) { function hasDenylistedType(path, state) {
if (path.node.type === state.type) { if (path.node.type === state.type) {
state.has = true; state.has = true;
path.stop(); path.stop();
} }
} }
traverse.hasType = function (tree, type, blacklistTypes) { traverse.hasType = function (tree, type, denylistTypes) {
if ((0, _includes.default)(blacklistTypes, tree.type)) return false; if (denylistTypes != null && denylistTypes.includes(tree.type)) return false;
if (tree.type === type) return true; if (tree.type === type) return true;
const state = { const state = {
has: false, has: false,
...@@ -111,8 +103,8 @@ traverse.hasType = function (tree, type, blacklistTypes) { ...@@ -111,8 +103,8 @@ traverse.hasType = function (tree, type, blacklistTypes) {
}; };
traverse(tree, { traverse(tree, {
noScope: true, noScope: true,
blacklist: blacklistTypes, denylist: denylistTypes,
enter: hasBlacklistedType enter: hasDenylistedType
}, null, state); }, null, state);
return state.has; return state.has;
}; };
......
...@@ -14,15 +14,9 @@ exports.isAncestor = isAncestor; ...@@ -14,15 +14,9 @@ exports.isAncestor = isAncestor;
exports.isDescendant = isDescendant; exports.isDescendant = isDescendant;
exports.inType = inType; exports.inType = inType;
var t = _interopRequireWildcard(require("@babel/types")); var t = require("@babel/types");
var _index = _interopRequireDefault(require("./index")); var _index = require("./index");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 findParent(callback) { function findParent(callback) {
let path = this; let path = this;
...@@ -167,11 +161,11 @@ function isDescendant(maybeAncestor) { ...@@ -167,11 +161,11 @@ function isDescendant(maybeAncestor) {
return !!this.findParent(parent => parent === maybeAncestor); return !!this.findParent(parent => parent === maybeAncestor);
} }
function inType() { function inType(...candidateTypes) {
let path = this; let path = this;
while (path) { while (path) {
for (const type of arguments) { for (const type of candidateTypes) {
if (path.node.type === type) return true; if (path.node.type === type) return true;
} }
......
...@@ -7,11 +7,7 @@ exports.shareCommentsWithSiblings = shareCommentsWithSiblings; ...@@ -7,11 +7,7 @@ exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
exports.addComment = addComment; exports.addComment = addComment;
exports.addComments = addComments; exports.addComments = addComments;
var t = _interopRequireWildcard(require("@babel/types")); var t = 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 shareCommentsWithSiblings() { function shareCommentsWithSiblings() {
if (typeof this.key === "string") return; if (typeof this.key === "string") return;
...@@ -25,9 +21,9 @@ function shareCommentsWithSiblings() { ...@@ -25,9 +21,9 @@ function shareCommentsWithSiblings() {
const hasPrev = Boolean(prev.node); const hasPrev = Boolean(prev.node);
const hasNext = Boolean(next.node); const hasNext = Boolean(next.node);
if (hasPrev && hasNext) {} else if (hasPrev) { if (hasPrev && !hasNext) {
prev.addComments("trailing", trailing); prev.addComments("trailing", trailing);
} else if (hasNext) { } else if (hasNext && !hasPrev) {
next.addComments("leading", leading); next.addComments("leading", leading);
} }
} }
......
...@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { ...@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
}); });
exports.call = call; exports.call = call;
exports._call = _call; exports._call = _call;
exports.isBlacklisted = isBlacklisted; exports.isBlacklisted = exports.isDenylisted = isDenylisted;
exports.visit = visit; exports.visit = visit;
exports.skip = skip; exports.skip = skip;
exports.skipKey = skipKey; exports.skipKey = skipKey;
...@@ -24,12 +24,10 @@ exports.setKey = setKey; ...@@ -24,12 +24,10 @@ exports.setKey = setKey;
exports.requeue = requeue; exports.requeue = requeue;
exports._getQueueContexts = _getQueueContexts; exports._getQueueContexts = _getQueueContexts;
var _index = _interopRequireDefault(require("../index")); var _index = require("../index");
var _index2 = require("./index"); var _index2 = require("./index");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function call(key) { function call(key) {
const opts = this.opts; const opts = this.opts;
this.debug(key); this.debug(key);
...@@ -69,9 +67,11 @@ function _call(fns) { ...@@ -69,9 +67,11 @@ function _call(fns) {
return false; return false;
} }
function isBlacklisted() { function isDenylisted() {
const blacklist = this.opts.blacklist; var _this$opts$denylist;
return blacklist && blacklist.indexOf(this.node.type) > -1;
const denylist = (_this$opts$denylist = this.opts.denylist) != null ? _this$opts$denylist : this.opts.blacklist;
return denylist && denylist.indexOf(this.node.type) > -1;
} }
function visit() { function visit() {
...@@ -79,7 +79,7 @@ function visit() { ...@@ -79,7 +79,7 @@ function visit() {
return false; return false;
} }
if (this.isBlacklisted()) { if (this.isDenylisted()) {
return false; return false;
} }
...@@ -119,6 +119,7 @@ function stop() { ...@@ -119,6 +119,7 @@ function stop() {
function setScope() { function setScope() {
if (this.opts && this.opts.noScope) return; if (this.opts && this.opts.noScope) return;
let path = this.parentPath; let path = this.parentPath;
if (this.key === "key" && path.isMethod()) path = path.parentPath;
let target; let target;
while (path && !target) { while (path && !target) {
...@@ -221,13 +222,16 @@ function setup(parentPath, container, listKey, key) { ...@@ -221,13 +222,16 @@ function setup(parentPath, container, listKey, key) {
} }
function setKey(key) { function setKey(key) {
var _this$node;
this.key = key; this.key = key;
this.node = this.container[this.key]; this.node = this.container[this.key];
this.type = this.node && this.node.type; this.type = (_this$node = this.node) == null ? void 0 : _this$node.type;
} }
function requeue(pathToQueue = this) { function requeue(pathToQueue = this) {
if (pathToQueue.removed) return; if (pathToQueue.removed) return;
;
const contexts = this.contexts; const contexts = this.contexts;
for (const context of contexts) { for (const context of contexts) {
......
...@@ -9,29 +9,22 @@ exports.arrowFunctionToShadowed = arrowFunctionToShadowed; ...@@ -9,29 +9,22 @@ exports.arrowFunctionToShadowed = arrowFunctionToShadowed;
exports.unwrapFunctionEnvironment = unwrapFunctionEnvironment; exports.unwrapFunctionEnvironment = unwrapFunctionEnvironment;
exports.arrowFunctionToExpression = arrowFunctionToExpression; exports.arrowFunctionToExpression = arrowFunctionToExpression;
var t = _interopRequireWildcard(require("@babel/types")); var t = require("@babel/types");
var _helperFunctionName = _interopRequireDefault(require("@babel/helper-function-name")); var _helperFunctionName = require("@babel/helper-function-name");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 toComputedKey() { function toComputedKey() {
const node = this.node;
let key; let key;
if (this.isMemberExpression()) { if (this.isMemberExpression()) {
key = node.property; key = this.node.property;
} else if (this.isProperty() || this.isMethod()) { } else if (this.isProperty() || this.isMethod()) {
key = node.key; key = this.node.key;
} else { } else {
throw new ReferenceError("todo"); throw new ReferenceError("todo");
} }
if (!node.computed) { if (!this.node.computed) {
if (t.isIdentifier(key)) key = t.stringLiteral(key.name); if (t.isIdentifier(key)) key = t.stringLiteral(key.name);
} }
...@@ -96,17 +89,18 @@ function unwrapFunctionEnvironment() { ...@@ -96,17 +89,18 @@ function unwrapFunctionEnvironment() {
function arrowFunctionToExpression({ function arrowFunctionToExpression({
allowInsertArrow = true, allowInsertArrow = true,
specCompliant = false specCompliant = false,
noNewArrows = !specCompliant
} = {}) { } = {}) {
if (!this.isArrowFunctionExpression()) { if (!this.isArrowFunctionExpression()) {
throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression."); throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression.");
} }
const thisBinding = hoistFunctionEnvironment(this, specCompliant, allowInsertArrow); const thisBinding = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow);
this.ensureBlock(); this.ensureBlock();
this.node.type = "FunctionExpression"; this.node.type = "FunctionExpression";
if (specCompliant) { if (!noNewArrows) {
const checkBinding = thisBinding ? null : this.parentPath.scope.generateUidIdentifier("arrowCheckId"); const checkBinding = thisBinding ? null : this.parentPath.scope.generateUidIdentifier("arrowCheckId");
if (checkBinding) { if (checkBinding) {
...@@ -121,13 +115,13 @@ function arrowFunctionToExpression({ ...@@ -121,13 +115,13 @@ function arrowFunctionToExpression({
} }
} }
function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArrow = true) { function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow = true) {
const thisEnvFn = fnPath.findParent(p => { const thisEnvFn = fnPath.findParent(p => {
return p.isFunction() && !p.isArrowFunctionExpression() || p.isProgram() || p.isClassProperty({ return p.isFunction() && !p.isArrowFunctionExpression() || p.isProgram() || p.isClassProperty({
static: false static: false
}); });
}); });
const inConstructor = thisEnvFn && thisEnvFn.node.kind === "constructor"; const inConstructor = (thisEnvFn == null ? void 0 : thisEnvFn.node.kind) === "constructor";
if (thisEnvFn.isClassProperty()) { if (thisEnvFn.isClassProperty()) {
throw fnPath.buildCodeFrameError("Unable to transform arrow inside class property"); throw fnPath.buildCodeFrameError("Unable to transform arrow inside class property");
...@@ -231,16 +225,16 @@ function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArro ...@@ -231,16 +225,16 @@ function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArro
let thisBinding; let thisBinding;
if (thisPaths.length > 0 || specCompliant) { if (thisPaths.length > 0 || !noNewArrows) {
thisBinding = getThisBinding(thisEnvFn, inConstructor); thisBinding = getThisBinding(thisEnvFn, inConstructor);
if (!specCompliant || inConstructor && hasSuperClass(thisEnvFn)) { if (noNewArrows || inConstructor && hasSuperClass(thisEnvFn)) {
thisPaths.forEach(thisChild => { thisPaths.forEach(thisChild => {
const thisRef = thisChild.isJSX() ? t.jsxIdentifier(thisBinding) : t.identifier(thisBinding); const thisRef = thisChild.isJSX() ? t.jsxIdentifier(thisBinding) : t.identifier(thisBinding);
thisRef.loc = thisChild.node.loc; thisRef.loc = thisChild.node.loc;
thisChild.replaceWith(thisRef); thisChild.replaceWith(thisRef);
}); });
if (specCompliant) thisBinding = null; if (!noNewArrows) thisBinding = null;
} }
} }
......
...@@ -55,9 +55,6 @@ function evaluateCached(path, state) { ...@@ -55,9 +55,6 @@ function evaluateCached(path, state) {
function _evaluate(path, state) { function _evaluate(path, state) {
if (!state.confident) return; if (!state.confident) return;
const {
node
} = path;
if (path.isSequenceExpression()) { if (path.isSequenceExpression()) {
const exprs = path.get("expressions"); const exprs = path.get("expressions");
...@@ -65,7 +62,7 @@ function _evaluate(path, state) { ...@@ -65,7 +62,7 @@ function _evaluate(path, state) {
} }
if (path.isStringLiteral() || path.isNumericLiteral() || path.isBooleanLiteral()) { if (path.isStringLiteral() || path.isNumericLiteral() || path.isBooleanLiteral()) {
return node.value; return path.node.value;
} }
if (path.isNullLiteral()) { if (path.isNullLiteral()) {
...@@ -73,7 +70,7 @@ function _evaluate(path, state) { ...@@ -73,7 +70,7 @@ function _evaluate(path, state) {
} }
if (path.isTemplateLiteral()) { if (path.isTemplateLiteral()) {
return evaluateQuasis(path, node.quasis, state); return evaluateQuasis(path, path.node.quasis, state);
} }
if (path.isTaggedTemplateExpression() && path.get("tag").isMemberExpression()) { if (path.isTaggedTemplateExpression() && path.get("tag").isMemberExpression()) {
...@@ -85,8 +82,8 @@ function _evaluate(path, state) { ...@@ -85,8 +82,8 @@ function _evaluate(path, state) {
} = object; } = object;
const property = path.get("tag.property"); const property = path.get("tag.property");
if (object.isIdentifier() && name === "String" && !path.scope.getBinding(name, true) && property.isIdentifier && property.node.name === "raw") { if (object.isIdentifier() && name === "String" && !path.scope.getBinding(name) && property.isIdentifier() && property.node.name === "raw") {
return evaluateQuasis(path, node.quasi.quasis, state, true); return evaluateQuasis(path, path.node.quasi.quasis, state, true);
} }
} }
...@@ -106,7 +103,7 @@ function _evaluate(path, state) { ...@@ -106,7 +103,7 @@ function _evaluate(path, state) {
} }
if (path.isMemberExpression() && !path.parentPath.isCallExpression({ if (path.isMemberExpression() && !path.parentPath.isCallExpression({
callee: node callee: path.node
})) { })) {
const property = path.get("property"); const property = path.get("property");
const object = path.get("object"); const object = path.get("object");
...@@ -122,7 +119,7 @@ function _evaluate(path, state) { ...@@ -122,7 +119,7 @@ function _evaluate(path, state) {
} }
if (path.isReferencedIdentifier()) { if (path.isReferencedIdentifier()) {
const binding = path.scope.getBinding(node.name); const binding = path.scope.getBinding(path.node.name);
if (binding && binding.constantViolations.length > 0) { if (binding && binding.constantViolations.length > 0) {
return deopt(binding.path, state); return deopt(binding.path, state);
...@@ -132,14 +129,14 @@ function _evaluate(path, state) { ...@@ -132,14 +129,14 @@ function _evaluate(path, state) {
return deopt(binding.path, state); return deopt(binding.path, state);
} }
if (binding && binding.hasValue) { if (binding != null && binding.hasValue) {
return binding.value; return binding.value;
} else { } else {
if (node.name === "undefined") { if (path.node.name === "undefined") {
return binding ? deopt(binding.path, state) : undefined; return binding ? deopt(binding.path, state) : undefined;
} else if (node.name === "Infinity") { } else if (path.node.name === "Infinity") {
return binding ? deopt(binding.path, state) : Infinity; return binding ? deopt(binding.path, state) : Infinity;
} else if (node.name === "NaN") { } else if (path.node.name === "NaN") {
return binding ? deopt(binding.path, state) : NaN; return binding ? deopt(binding.path, state) : NaN;
} }
...@@ -156,20 +153,20 @@ function _evaluate(path, state) { ...@@ -156,20 +153,20 @@ function _evaluate(path, state) {
if (path.isUnaryExpression({ if (path.isUnaryExpression({
prefix: true prefix: true
})) { })) {
if (node.operator === "void") { if (path.node.operator === "void") {
return undefined; return undefined;
} }
const argument = path.get("argument"); const argument = path.get("argument");
if (node.operator === "typeof" && (argument.isFunction() || argument.isClass())) { if (path.node.operator === "typeof" && (argument.isFunction() || argument.isClass())) {
return "function"; return "function";
} }
const arg = evaluateCached(argument, state); const arg = evaluateCached(argument, state);
if (!state.confident) return; if (!state.confident) return;
switch (node.operator) { switch (path.node.operator) {
case "!": case "!":
return !arg; return !arg;
...@@ -197,7 +194,7 @@ function _evaluate(path, state) { ...@@ -197,7 +194,7 @@ function _evaluate(path, state) {
if (elemValue.confident) { if (elemValue.confident) {
arr.push(elemValue.value); arr.push(elemValue.value);
} else { } else {
return deopt(elem, state); return deopt(elemValue.deopt, state);
} }
} }
...@@ -220,7 +217,7 @@ function _evaluate(path, state) { ...@@ -220,7 +217,7 @@ function _evaluate(path, state) {
key = key.evaluate(); key = key.evaluate();
if (!key.confident) { if (!key.confident) {
return deopt(keyPath, state); return deopt(key.deopt, state);
} }
key = key.value; key = key.value;
...@@ -234,7 +231,7 @@ function _evaluate(path, state) { ...@@ -234,7 +231,7 @@ function _evaluate(path, state) {
let value = valuePath.evaluate(); let value = valuePath.evaluate();
if (!value.confident) { if (!value.confident) {
return deopt(valuePath, state); return deopt(value.deopt, state);
} }
value = value.value; value = value.value;
...@@ -252,7 +249,7 @@ function _evaluate(path, state) { ...@@ -252,7 +249,7 @@ function _evaluate(path, state) {
const right = evaluateCached(path.get("right"), state); const right = evaluateCached(path.get("right"), state);
const rightConfident = state.confident; const rightConfident = state.confident;
switch (node.operator) { switch (path.node.operator) {
case "||": case "||":
state.confident = leftConfident && (!!left || rightConfident); state.confident = leftConfident && (!!left || rightConfident);
if (!state.confident) return; if (!state.confident) return;
...@@ -271,7 +268,7 @@ function _evaluate(path, state) { ...@@ -271,7 +268,7 @@ function _evaluate(path, state) {
const right = evaluateCached(path.get("right"), state); const right = evaluateCached(path.get("right"), state);
if (!state.confident) return; if (!state.confident) return;
switch (node.operator) { switch (path.node.operator) {
case "-": case "-":
return left - right; return left - right;
...@@ -339,8 +336,8 @@ function _evaluate(path, state) { ...@@ -339,8 +336,8 @@ function _evaluate(path, state) {
let context; let context;
let func; let func;
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) && VALID_CALLEES.indexOf(callee.node.name) >= 0) { if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) && VALID_CALLEES.indexOf(callee.node.name) >= 0) {
func = global[node.callee.name]; func = global[callee.node.name];
} }
if (callee.isMemberExpression()) { if (callee.isMemberExpression()) {
......
...@@ -18,15 +18,26 @@ exports.getOuterBindingIdentifiers = getOuterBindingIdentifiers; ...@@ -18,15 +18,26 @@ exports.getOuterBindingIdentifiers = getOuterBindingIdentifiers;
exports.getBindingIdentifierPaths = getBindingIdentifierPaths; exports.getBindingIdentifierPaths = getBindingIdentifierPaths;
exports.getOuterBindingIdentifierPaths = getOuterBindingIdentifierPaths; exports.getOuterBindingIdentifierPaths = getOuterBindingIdentifierPaths;
var _index = _interopRequireDefault(require("./index")); var _index = require("./index");
var t = _interopRequireWildcard(require("@babel/types")); var t = require("@babel/types");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } const NORMAL_COMPLETION = 0;
const BREAK_COMPLETION = 1;
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 NormalCompletion(path) {
return {
type: NORMAL_COMPLETION,
path
};
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function BreakCompletion(path) {
return {
type: BREAK_COMPLETION,
path
};
}
function getOpposite() { function getOpposite() {
if (this.key === "left") { if (this.key === "left") {
...@@ -34,88 +45,167 @@ function getOpposite() { ...@@ -34,88 +45,167 @@ function getOpposite() {
} else if (this.key === "right") { } else if (this.key === "right") {
return this.getSibling("left"); return this.getSibling("left");
} }
return null;
} }
function addCompletionRecords(path, paths) { function addCompletionRecords(path, records, context) {
if (path) return paths.concat(path.getCompletionRecords()); if (path) return records.concat(_getCompletionRecords(path, context));
return paths; return records;
} }
function completionRecordForSwitch(cases, paths) { function completionRecordForSwitch(cases, records, context) {
let isLastCaseWithConsequent = true; let lastNormalCompletions = [];
for (let i = cases.length - 1; i >= 0; i--) { for (let i = 0; i < cases.length; i++) {
const switchCase = cases[i]; const casePath = cases[i];
const consequent = switchCase.get("consequent");
let breakStatement;
findBreak: for (const statement of consequent) { const caseCompletions = _getCompletionRecords(casePath, context);
if (statement.isBlockStatement()) {
for (const statementInBlock of statement.get("body")) { const normalCompletions = [];
if (statementInBlock.isBreakStatement()) { const breakCompletions = [];
breakStatement = statementInBlock;
break findBreak; for (const c of caseCompletions) {
} if (c.type === NORMAL_COMPLETION) {
} normalCompletions.push(c);
} else if (statement.isBreakStatement()) {
breakStatement = statement;
break;
} }
}
if (breakStatement) { if (c.type === BREAK_COMPLETION) {
while (breakStatement.key === 0 && breakStatement.parentPath.isBlockStatement()) { breakCompletions.push(c);
breakStatement = breakStatement.parentPath;
} }
}
if (normalCompletions.length) {
lastNormalCompletions = normalCompletions;
}
records = records.concat(breakCompletions);
}
const prevSibling = breakStatement.getPrevSibling(); records = records.concat(lastNormalCompletions);
return records;
}
if (breakStatement.key > 0 && (prevSibling.isExpressionStatement() || prevSibling.isBlockStatement())) { function normalCompletionToBreak(completions) {
paths = addCompletionRecords(prevSibling, paths); completions.forEach(c => {
breakStatement.remove(); c.type = BREAK_COMPLETION;
});
}
function replaceBreakStatementInBreakCompletion(completions, reachable) {
completions.forEach(c => {
if (c.path.isBreakStatement({
label: null
})) {
if (reachable) {
c.path.replaceWith(t.unaryExpression("void", t.numericLiteral(0)));
} else { } else {
breakStatement.replaceWith(breakStatement.scope.buildUndefinedNode()); c.path.remove();
paths = addCompletionRecords(breakStatement, paths); }
}
});
}
function getStatementListCompletion(paths, context) {
let completions = [];
if (context.canHaveBreak) {
let lastNormalCompletions = [];
for (let i = 0; i < paths.length; i++) {
const path = paths[i];
const newContext = Object.assign({}, context, {
inCaseClause: false
});
if (path.isBlockStatement() && (context.inCaseClause || context.shouldPopulateBreak)) {
newContext.shouldPopulateBreak = true;
} else {
newContext.shouldPopulateBreak = false;
} }
} else if (isLastCaseWithConsequent) {
const statementFinder = statement => !statement.isBlockStatement() || statement.get("body").some(statementFinder);
const hasConsequent = consequent.some(statementFinder); const statementCompletions = _getCompletionRecords(path, newContext);
if (statementCompletions.length > 0 && statementCompletions.every(c => c.type === BREAK_COMPLETION)) {
if (lastNormalCompletions.length > 0 && statementCompletions.every(c => c.path.isBreakStatement({
label: null
}))) {
normalCompletionToBreak(lastNormalCompletions);
completions = completions.concat(lastNormalCompletions);
if (lastNormalCompletions.some(c => c.path.isDeclaration())) {
completions = completions.concat(statementCompletions);
replaceBreakStatementInBreakCompletion(statementCompletions, true);
}
replaceBreakStatementInBreakCompletion(statementCompletions, false);
} else {
completions = completions.concat(statementCompletions);
if (!context.shouldPopulateBreak) {
replaceBreakStatementInBreakCompletion(statementCompletions, true);
}
}
break;
}
if (hasConsequent) { if (i === paths.length - 1) {
paths = addCompletionRecords(consequent[consequent.length - 1], paths); completions = completions.concat(statementCompletions);
isLastCaseWithConsequent = false; } else {
completions = completions.concat(statementCompletions.filter(c => c.type === BREAK_COMPLETION));
lastNormalCompletions = statementCompletions.filter(c => c.type === NORMAL_COMPLETION);
} }
} }
} else if (paths.length) {
completions = completions.concat(_getCompletionRecords(paths[paths.length - 1], context));
} }
return paths; return completions;
} }
function getCompletionRecords() { function _getCompletionRecords(path, context) {
let paths = []; let records = [];
if (this.isIfStatement()) { if (path.isIfStatement()) {
paths = addCompletionRecords(this.get("consequent"), paths); records = addCompletionRecords(path.get("consequent"), records, context);
paths = addCompletionRecords(this.get("alternate"), paths); records = addCompletionRecords(path.get("alternate"), records, context);
} else if (this.isDoExpression() || this.isFor() || this.isWhile()) { } else if (path.isDoExpression() || path.isFor() || path.isWhile() || path.isLabeledStatement()) {
paths = addCompletionRecords(this.get("body"), paths); records = addCompletionRecords(path.get("body"), records, context);
} else if (this.isProgram() || this.isBlockStatement()) { } else if (path.isProgram() || path.isBlockStatement()) {
paths = addCompletionRecords(this.get("body").pop(), paths); records = records.concat(getStatementListCompletion(path.get("body"), context));
} else if (this.isFunction()) { } else if (path.isFunction()) {
return this.get("body").getCompletionRecords(); return _getCompletionRecords(path.get("body"), context);
} else if (this.isTryStatement()) { } else if (path.isTryStatement()) {
paths = addCompletionRecords(this.get("block"), paths); records = addCompletionRecords(path.get("block"), records, context);
paths = addCompletionRecords(this.get("handler"), paths); records = addCompletionRecords(path.get("handler"), records, context);
} else if (this.isCatchClause()) { } else if (path.isCatchClause()) {
paths = addCompletionRecords(this.get("body"), paths); records = addCompletionRecords(path.get("body"), records, context);
} else if (this.isSwitchStatement()) { } else if (path.isSwitchStatement()) {
paths = completionRecordForSwitch(this.get("cases"), paths); records = completionRecordForSwitch(path.get("cases"), records, context);
} else if (path.isSwitchCase()) {
records = records.concat(getStatementListCompletion(path.get("consequent"), {
canHaveBreak: true,
shouldPopulateBreak: false,
inCaseClause: true
}));
} else if (path.isBreakStatement()) {
records.push(BreakCompletion(path));
} else { } else {
paths.push(this); records.push(NormalCompletion(path));
} }
return paths; return records;
}
function getCompletionRecords() {
const records = _getCompletionRecords(this, {
canHaveBreak: false,
shouldPopulateBreak: false,
inCaseClause: false
});
return records.map(r => r.path);
} }
function getSibling(key) { function getSibling(key) {
...@@ -125,7 +215,7 @@ function getSibling(key) { ...@@ -125,7 +215,7 @@ function getSibling(key) {
container: this.container, container: this.container,
listKey: this.listKey, listKey: this.listKey,
key: key key: key
}); }).setContext(this.context);
} }
function getPrevSibling() { function getPrevSibling() {
...@@ -162,7 +252,7 @@ function getAllPrevSiblings() { ...@@ -162,7 +252,7 @@ function getAllPrevSiblings() {
return siblings; return siblings;
} }
function get(key, context) { function get(key, context = true) {
if (context === true) context = this.context; if (context === true) context = this.context;
const parts = key.split("."); const parts = key.split(".");
......
...@@ -5,49 +5,44 @@ Object.defineProperty(exports, "__esModule", { ...@@ -5,49 +5,44 @@ Object.defineProperty(exports, "__esModule", {
}); });
exports.default = exports.SHOULD_SKIP = exports.SHOULD_STOP = exports.REMOVED = void 0; exports.default = exports.SHOULD_SKIP = exports.SHOULD_STOP = exports.REMOVED = void 0;
var virtualTypes = _interopRequireWildcard(require("./lib/virtual-types")); var virtualTypes = require("./lib/virtual-types");
var _debug = _interopRequireDefault(require("debug")); var _debug = require("debug");
var _index = _interopRequireDefault(require("../index")); var _index = require("../index");
var _scope = _interopRequireDefault(require("../scope")); var _scope = require("../scope");
var t = _interopRequireWildcard(require("@babel/types")); var t = require("@babel/types");
var _cache = require("../cache"); var _cache = require("../cache");
var _generator = _interopRequireDefault(require("@babel/generator")); var _generator = require("@babel/generator");
var NodePath_ancestry = _interopRequireWildcard(require("./ancestry")); var NodePath_ancestry = require("./ancestry");
var NodePath_inference = _interopRequireWildcard(require("./inference")); var NodePath_inference = require("./inference");
var NodePath_replacement = _interopRequireWildcard(require("./replacement")); var NodePath_replacement = require("./replacement");
var NodePath_evaluation = _interopRequireWildcard(require("./evaluation")); var NodePath_evaluation = require("./evaluation");
var NodePath_conversion = _interopRequireWildcard(require("./conversion")); var NodePath_conversion = require("./conversion");
var NodePath_introspection = _interopRequireWildcard(require("./introspection")); var NodePath_introspection = require("./introspection");
var NodePath_context = _interopRequireWildcard(require("./context")); var NodePath_context = require("./context");
var NodePath_removal = _interopRequireWildcard(require("./removal")); var NodePath_removal = require("./removal");
var NodePath_modification = _interopRequireWildcard(require("./modification")); var NodePath_modification = require("./modification");
var NodePath_family = _interopRequireWildcard(require("./family")); var NodePath_family = require("./family");
var NodePath_comments = _interopRequireWildcard(require("./comments")); var NodePath_comments = require("./comments");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const debug = _debug("babel");
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; }
const debug = (0, _debug.default)("babel");
const REMOVED = 1 << 0; const REMOVED = 1 << 0;
exports.REMOVED = REMOVED; exports.REMOVED = REMOVED;
const SHOULD_STOP = 1 << 1; const SHOULD_STOP = 1 << 1;
...@@ -57,22 +52,22 @@ exports.SHOULD_SKIP = SHOULD_SKIP; ...@@ -57,22 +52,22 @@ exports.SHOULD_SKIP = SHOULD_SKIP;
class NodePath { class NodePath {
constructor(hub, parent) { constructor(hub, parent) {
this.parent = parent;
this.hub = hub;
this.contexts = []; this.contexts = [];
this.data = null;
this._traverseFlags = 0;
this.state = null; this.state = null;
this.opts = null; this.opts = null;
this._traverseFlags = 0;
this.skipKeys = null; this.skipKeys = null;
this.parentPath = null; this.parentPath = null;
this.context = null;
this.container = null; this.container = null;
this.listKey = null; this.listKey = null;
this.key = null; this.key = null;
this.node = null; this.node = null;
this.scope = null;
this.type = null; this.type = null;
this.parent = parent;
this.hub = hub;
this.data = null;
this.context = null;
this.scope = null;
} }
static get({ static get({
...@@ -92,26 +87,20 @@ class NodePath { ...@@ -92,26 +87,20 @@ class NodePath {
} }
const targetNode = container[key]; const targetNode = container[key];
const paths = _cache.path.get(parent) || [];
if (!_cache.path.has(parent)) {
_cache.path.set(parent, paths);
}
let path; let paths = _cache.path.get(parent);
for (let i = 0; i < paths.length; i++) { if (!paths) {
const pathCheck = paths[i]; paths = new Map();
if (pathCheck.node === targetNode) { _cache.path.set(parent, paths);
path = pathCheck;
break;
}
} }
let path = paths.get(targetNode);
if (!path) { if (!path) {
path = new NodePath(hub, parent); path = new NodePath(hub, parent);
paths.push(path); if (targetNode) paths.set(targetNode, path);
} }
path.setup(parentPath, container, listKey, key); path.setup(parentPath, container, listKey, key);
...@@ -227,7 +216,6 @@ class NodePath { ...@@ -227,7 +216,6 @@ class NodePath {
} }
exports.default = NodePath;
Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments); Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments);
for (const type of t.TYPES) { for (const type of t.TYPES) {
...@@ -253,4 +241,7 @@ for (const type of Object.keys(virtualTypes)) { ...@@ -253,4 +241,7 @@ for (const type of Object.keys(virtualTypes)) {
NodePath.prototype[`is${type}`] = function (opts) { NodePath.prototype[`is${type}`] = function (opts) {
return virtualType.checkPath(this, opts); return virtualType.checkPath(this, opts);
}; };
} }
\ No newline at end of file
var _default = NodePath;
exports.default = _default;
\ No newline at end of file
...@@ -10,13 +10,9 @@ exports.couldBeBaseType = couldBeBaseType; ...@@ -10,13 +10,9 @@ exports.couldBeBaseType = couldBeBaseType;
exports.baseTypeStrictlyMatches = baseTypeStrictlyMatches; exports.baseTypeStrictlyMatches = baseTypeStrictlyMatches;
exports.isGenericType = isGenericType; exports.isGenericType = isGenericType;
var inferers = _interopRequireWildcard(require("./inferers")); var inferers = require("./inferers");
var t = _interopRequireWildcard(require("@babel/types")); var t = 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 getTypeAnnotation() { function getTypeAnnotation() {
if (this.typeAnnotation) return this.typeAnnotation; if (this.typeAnnotation) return this.typeAnnotation;
...@@ -25,6 +21,8 @@ function getTypeAnnotation() { ...@@ -25,6 +21,8 @@ function getTypeAnnotation() {
return this.typeAnnotation = type; return this.typeAnnotation = type;
} }
const typeAnnotationInferringNodes = new WeakSet();
function _getTypeAnnotation() { function _getTypeAnnotation() {
const node = this.node; const node = this.node;
...@@ -51,16 +49,28 @@ function _getTypeAnnotation() { ...@@ -51,16 +49,28 @@ function _getTypeAnnotation() {
return node.typeAnnotation; return node.typeAnnotation;
} }
let inferer = inferers[node.type]; if (typeAnnotationInferringNodes.has(node)) {
return;
if (inferer) {
return inferer.call(this, node);
} }
inferer = inferers[this.parentPath.type]; typeAnnotationInferringNodes.add(node);
try {
var _inferer;
let inferer = inferers[node.type];
if (inferer && inferer.validParent) { if (inferer) {
return this.parentPath.getTypeAnnotation(); return inferer.call(this, node);
}
inferer = inferers[this.parentPath.type];
if ((_inferer = inferer) != null && _inferer.validParent) {
return this.parentPath.getTypeAnnotation();
}
} finally {
typeAnnotationInferringNodes.delete(node);
} }
} }
...@@ -109,13 +119,15 @@ function couldBeBaseType(name) { ...@@ -109,13 +119,15 @@ function couldBeBaseType(name) {
} }
} }
function baseTypeStrictlyMatches(right) { function baseTypeStrictlyMatches(rightArg) {
const left = this.getTypeAnnotation(); const left = this.getTypeAnnotation();
right = right.getTypeAnnotation(); const right = rightArg.getTypeAnnotation();
if (!t.isAnyTypeAnnotation(left) && t.isFlowBaseAnnotation(left)) { if (!t.isAnyTypeAnnotation(left) && t.isFlowBaseAnnotation(left)) {
return right.type === left.type; return right.type === left.type;
} }
return false;
} }
function isGenericType(genericName) { function isGenericType(genericName) {
......
...@@ -5,11 +5,7 @@ Object.defineProperty(exports, "__esModule", { ...@@ -5,11 +5,7 @@ Object.defineProperty(exports, "__esModule", {
}); });
exports.default = _default; exports.default = _default;
var t = _interopRequireWildcard(require("@babel/types")); var t = 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 _default(node) { function _default(node) {
if (!this.isReferenced()) return; if (!this.isReferenced()) return;
...@@ -50,9 +46,19 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) { ...@@ -50,9 +46,19 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
} }
} }
if (types.length) { if (!types.length) {
return t.createUnionTypeAnnotation(types); return;
} }
if (t.isTSTypeAnnotation(types[0]) && t.createTSUnionType) {
return t.createTSUnionType(types);
}
if (t.createFlowUnionType) {
return t.createFlowUnionType(types);
}
return t.createUnionTypeAnnotation(types);
} }
function getConstantViolationsBefore(binding, path, functions) { function getConstantViolationsBefore(binding, path, functions) {
...@@ -165,6 +171,20 @@ function getConditionalAnnotation(binding, path, name) { ...@@ -165,6 +171,20 @@ function getConditionalAnnotation(binding, path, name) {
} }
if (types.length) { if (types.length) {
if (t.isTSTypeAnnotation(types[0]) && t.createTSUnionType) {
return {
typeAnnotation: t.createTSUnionType(types),
ifStatement
};
}
if (t.createFlowUnionType) {
return {
typeAnnotation: t.createFlowUnionType(types),
ifStatement
};
}
return { return {
typeAnnotation: t.createUnionTypeAnnotation(types), typeAnnotation: t.createUnionTypeAnnotation(types),
ifStatement ifStatement
......
...@@ -33,23 +33,19 @@ Object.defineProperty(exports, "Identifier", { ...@@ -33,23 +33,19 @@ Object.defineProperty(exports, "Identifier", {
} }
}); });
var t = _interopRequireWildcard(require("@babel/types")); var t = require("@babel/types");
var _infererReference = _interopRequireDefault(require("./inferer-reference")); var _infererReference = require("./inferer-reference");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 VariableDeclarator() { function VariableDeclarator() {
var _type;
const id = this.get("id"); const id = this.get("id");
if (!id.isIdentifier()) return; if (!id.isIdentifier()) return;
const init = this.get("init"); const init = this.get("init");
let type = init.getTypeAnnotation(); let type = init.getTypeAnnotation();
if (type && type.type === "AnyTypeAnnotation") { if (((_type = type) == null ? void 0 : _type.type) === "AnyTypeAnnotation") {
if (init.isCallExpression() && init.get("callee").isIdentifier({ if (init.isCallExpression() && init.get("callee").isIdentifier({
name: "Array" name: "Array"
}) && !init.scope.hasBinding("Array", true)) { }) && !init.scope.hasBinding("Array", true)) {
...@@ -112,11 +108,31 @@ function BinaryExpression(node) { ...@@ -112,11 +108,31 @@ function BinaryExpression(node) {
} }
function LogicalExpression() { function LogicalExpression() {
return t.createUnionTypeAnnotation([this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()]); const argumentTypes = [this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()];
if (t.isTSTypeAnnotation(argumentTypes[0]) && t.createTSUnionType) {
return t.createTSUnionType(argumentTypes);
}
if (t.createFlowUnionType) {
return t.createFlowUnionType(argumentTypes);
}
return t.createUnionTypeAnnotation(argumentTypes);
} }
function ConditionalExpression() { function ConditionalExpression() {
return t.createUnionTypeAnnotation([this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()]); const argumentTypes = [this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()];
if (t.isTSTypeAnnotation(argumentTypes[0]) && t.createTSUnionType) {
return t.createTSUnionType(argumentTypes);
}
if (t.createFlowUnionType) {
return t.createFlowUnionType(argumentTypes);
}
return t.createUnionTypeAnnotation(argumentTypes);
} }
function SequenceExpression() { function SequenceExpression() {
......
...@@ -24,15 +24,7 @@ exports.isConstantExpression = isConstantExpression; ...@@ -24,15 +24,7 @@ exports.isConstantExpression = isConstantExpression;
exports.isInStrictMode = isInStrictMode; exports.isInStrictMode = isInStrictMode;
exports.is = void 0; exports.is = void 0;
var _includes = _interopRequireDefault(require("lodash/includes")); var t = require("@babel/types");
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 }; }
function matchesPattern(pattern, allowPartial) { function matchesPattern(pattern, allowPartial) {
return t.matchesPattern(this.node, pattern, allowPartial); return t.matchesPattern(this.node, pattern, allowPartial);
...@@ -110,12 +102,22 @@ function isStatementOrBlock() { ...@@ -110,12 +102,22 @@ function isStatementOrBlock() {
if (this.parentPath.isLabeledStatement() || t.isBlockStatement(this.container)) { if (this.parentPath.isLabeledStatement() || t.isBlockStatement(this.container)) {
return false; return false;
} else { } else {
return (0, _includes.default)(t.STATEMENT_OR_BLOCK_KEYS, this.key); return t.STATEMENT_OR_BLOCK_KEYS.includes(this.key);
} }
} }
function referencesImport(moduleSource, importName) { function referencesImport(moduleSource, importName) {
if (!this.isReferencedIdentifier()) return false; if (!this.isReferencedIdentifier()) {
if ((this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? t.isStringLiteral(this.node.property, {
value: importName
}) : this.node.property.name === importName)) {
const object = this.get("object");
return object.isReferencedIdentifier() && object.referencesImport(moduleSource, "*");
}
return false;
}
const binding = this.scope.getBinding(this.node.name); const binding = this.scope.getBinding(this.node.name);
if (!binding || binding.kind !== "module") return false; if (!binding || binding.kind !== "module") return false;
const path = binding.path; const path = binding.path;
...@@ -136,7 +138,9 @@ function referencesImport(moduleSource, importName) { ...@@ -136,7 +138,9 @@ function referencesImport(moduleSource, importName) {
return true; return true;
} }
if (path.isImportSpecifier() && path.node.imported.name === importName) { if (path.isImportSpecifier() && t.isIdentifier(path.node.imported, {
name: importName
})) {
return true; return true;
} }
...@@ -381,7 +385,7 @@ function isConstantExpression() { ...@@ -381,7 +385,7 @@ function isConstantExpression() {
} }
if (this.isUnaryExpression()) { if (this.isUnaryExpression()) {
if (this.get("operator").node !== "void") { if (this.node.operator !== "void") {
return false; return false;
} }
...@@ -408,12 +412,9 @@ function isInStrictMode() { ...@@ -408,12 +412,9 @@ function isInStrictMode() {
return false; return false;
} }
let { const body = path.isFunction() ? path.node.body : path.node;
node
} = path;
if (path.isFunction()) node = node.body;
for (const directive of node.directives) { for (const directive of body.directives) {
if (directive.value.value === "use strict") { if (directive.value.value === "use strict") {
return true; return true;
} }
......
...@@ -5,11 +5,7 @@ Object.defineProperty(exports, "__esModule", { ...@@ -5,11 +5,7 @@ Object.defineProperty(exports, "__esModule", {
}); });
exports.default = void 0; exports.default = void 0;
var t = _interopRequireWildcard(require("@babel/types")); var t = 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; }
const referenceVisitor = { const referenceVisitor = {
ReferencedIdentifier(path, state) { ReferencedIdentifier(path, state) {
...@@ -48,6 +44,13 @@ const referenceVisitor = { ...@@ -48,6 +44,13 @@ const referenceVisitor = {
class PathHoister { class PathHoister {
constructor(path, scope) { constructor(path, scope) {
this.breakOnScopePaths = void 0;
this.bindings = void 0;
this.mutableBinding = void 0;
this.scopes = void 0;
this.scope = void 0;
this.path = void 0;
this.attachAfter = void 0;
this.breakOnScopePaths = []; this.breakOnScopePaths = [];
this.bindings = {}; this.bindings = {};
this.mutableBinding = false; this.mutableBinding = false;
...@@ -181,7 +184,7 @@ class PathHoister { ...@@ -181,7 +184,7 @@ class PathHoister {
const parent = this.path.parentPath; const parent = this.path.parentPath;
if (parent.isJSXElement() && this.path.container === parent.node.children) { if (parent.isJSXElement() && this.path.container === parent.node.children) {
uid = t.JSXExpressionContainer(uid); uid = t.jsxExpressionContainer(uid);
} }
this.path.replaceWith(t.cloneNode(uid)); this.path.replaceWith(t.cloneNode(uid));
......
...@@ -5,11 +5,7 @@ Object.defineProperty(exports, "__esModule", { ...@@ -5,11 +5,7 @@ Object.defineProperty(exports, "__esModule", {
}); });
exports.ForAwaitStatement = exports.NumericLiteralTypeAnnotation = exports.ExistentialTypeParam = exports.SpreadProperty = exports.RestProperty = exports.Flow = exports.Pure = exports.Generated = exports.User = exports.Var = exports.BlockScoped = exports.Referenced = exports.Scope = exports.Expression = exports.Statement = exports.BindingIdentifier = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = void 0; exports.ForAwaitStatement = exports.NumericLiteralTypeAnnotation = exports.ExistentialTypeParam = exports.SpreadProperty = exports.RestProperty = exports.Flow = exports.Pure = exports.Generated = exports.User = exports.Var = exports.BlockScoped = exports.Referenced = exports.Scope = exports.Expression = exports.Statement = exports.BindingIdentifier = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = void 0;
var t = _interopRequireWildcard(require("@babel/types")); var t = 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; }
const ReferencedIdentifier = { const ReferencedIdentifier = {
types: ["Identifier", "JSXIdentifier"], types: ["Identifier", "JSXIdentifier"],
...@@ -98,7 +94,7 @@ const Expression = { ...@@ -98,7 +94,7 @@ const Expression = {
}; };
exports.Expression = Expression; exports.Expression = Expression;
const Scope = { const Scope = {
types: ["Scopable"], types: ["Scopable", "Pattern"],
checkPath(path) { checkPath(path) {
return t.isScope(path.node, path.parent); return t.isScope(path.node, path.parent);
......
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