get rid of _let
This commit is contained in:
@@ -71,7 +71,7 @@ let buildRetCheck = template(`
|
||||
|
||||
function isBlockScoped(node) {
|
||||
if (!t.isVariableDeclaration(node)) return false;
|
||||
if (node._let) return true;
|
||||
if (node[t.BLOCK_SCOPED_SYMBOL]) return true;
|
||||
if (node.kind !== "let" && node.kind !== "const") return false;
|
||||
return true;
|
||||
}
|
||||
@@ -85,18 +85,13 @@ function convertBlockScopedToVar(node, parent, scope) {
|
||||
}
|
||||
}
|
||||
|
||||
node[t.BLOCK_SCOPED_SYMBOL] = true;
|
||||
node._let = true;
|
||||
node.kind = "var";
|
||||
}
|
||||
|
||||
function isVar(node, parent) {
|
||||
return t.isVariableDeclaration(node, { kind: "var" }) && !isBlockScoped(node, parent);
|
||||
}
|
||||
|
||||
function standardizeLets(declars) {
|
||||
for (let declar of (declars: Array)) {
|
||||
delete declar._let;
|
||||
}
|
||||
function isVar(node) {
|
||||
return t.isVariableDeclaration(node, { kind: "var" }) && !isBlockScoped(node);
|
||||
}
|
||||
|
||||
function replace(path, node, scope, remaps) {
|
||||
@@ -527,9 +522,6 @@ class BlockScoping {
|
||||
// no let references so we can just quit
|
||||
if (!this.hasLetReferences) return;
|
||||
|
||||
// set let references to plain let references
|
||||
standardizeLets(declarators);
|
||||
|
||||
let state = {
|
||||
letReferences: this.letReferences,
|
||||
closurify: false,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const deepAssign = function () {
|
||||
var deepAssign = function () {
|
||||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
@@ -22,3 +22,5 @@ export const INHERIT_KEYS = {
|
||||
optional: ["typeAnnotation", "typeParameters", "returnType"],
|
||||
force: ["start", "loc", "end"]
|
||||
};
|
||||
|
||||
export const BLOCK_SCOPED_SYMBOL = Symbol("var used to be block scoped");
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { getBindingIdentifiers } from "./retrievers";
|
||||
import esutils from "esutils";
|
||||
import * as t from "./index";
|
||||
import { BLOCK_SCOPED_SYMBOL } from "./constants";
|
||||
|
||||
/**
|
||||
* Check if the input `node` is a binding identifier.
|
||||
@@ -169,7 +170,7 @@ export function isValidIdentifier(name: string): boolean {
|
||||
*/
|
||||
|
||||
export function isLet(node: Object): boolean {
|
||||
return t.isVariableDeclaration(node) && (node.kind !== "var" || node._let);
|
||||
return t.isVariableDeclaration(node) && (node.kind !== "var" || node[BLOCK_SCOPED_SYMBOL]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,7 +186,7 @@ export function isBlockScoped(node: Object): boolean {
|
||||
*/
|
||||
|
||||
export function isVar(node: Object): boolean {
|
||||
return t.isVariableDeclaration(node, { kind: "var" }) && !node._let;
|
||||
return t.isVariableDeclaration(node, { kind: "var" }) && !node[BLOCK_SCOPED_SYMBOL];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user