simplify scope parent alias keys

This commit is contained in:
Sebastian McKenzie 2015-05-30 23:08:42 -04:00
parent 973270772b
commit 19c1ee157f
2 changed files with 23 additions and 24 deletions

View File

@ -708,7 +708,7 @@ export default class Scope {
getFunctionParent() { getFunctionParent() {
var scope = this; var scope = this;
do { do {
if (scope.path.isProgram() || scope.path.isFunction()) { if (scope.path.isFunctionParent()) {
return scope; return scope;
} }
} while (scope = scope.parent); } while (scope = scope.parent);
@ -723,15 +723,11 @@ export default class Scope {
getBlockParent() { getBlockParent() {
var scope = this; var scope = this;
do { do {
if (scope.path.isProgram() || if (scope.path.isBlockParent()) {
scope.path.isBlockStatement() ||
scope.path.isFunction() ||
scope.path.isLoop() ||
scope.path.isSwitchStatement()) {
return scope; return scope;
} }
} while (scope = scope.parent); } while (scope = scope.parent);
throw new Error("We couldn't find a BlockStatement, For or Program..."); throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
} }
/** /**

View File

@ -1,20 +1,22 @@
{ {
"ExpressionStatement": ["Statement"], "ExpressionStatement": ["Statement"],
"BreakStatement": ["Statement", "Terminatorless"],
"ContinueStatement": ["Statement", "Terminatorless"],
"DebuggerStatement": ["Statement"], "DebuggerStatement": ["Statement"],
"DoWhileStatement": ["Statement", "Loop", "While", "Scopable"],
"IfStatement": ["Statement"], "IfStatement": ["Statement"],
"ReturnStatement": ["Statement", "Terminatorless"],
"SwitchStatement": ["Statement", "Scopable"],
"ThrowStatement": ["Statement", "Terminatorless"],
"TryStatement": ["Statement"], "TryStatement": ["Statement"],
"WhileStatement": ["Statement", "Loop", "While", "Scopable"],
"WithStatement": ["Statement"], "WithStatement": ["Statement"],
"EmptyStatement": ["Statement"], "EmptyStatement": ["Statement"],
"LabeledStatement": ["Statement"], "LabeledStatement": ["Statement"],
"VariableDeclaration": ["Statement", "Declaration"], "VariableDeclaration": ["Statement", "Declaration"],
"BreakStatement": ["Statement", "Terminatorless"],
"ContinueStatement": ["Statement", "Terminatorless"],
"ReturnStatement": ["Statement", "Terminatorless"],
"ThrowStatement": ["Statement", "Terminatorless"],
"DoWhileStatement": ["Statement", "BlockParent", "Loop", "While", "Scopable"],
"WhileStatement": ["Statement", "BlockParent", "Loop", "While", "Scopable"],
"SwitchStatement": ["Statement", "BlockParent", "Scopable"],
"ImportSpecifier": ["ModuleSpecifier"], "ImportSpecifier": ["ModuleSpecifier"],
"ExportSpecifier": ["ModuleSpecifier"], "ExportSpecifier": ["ModuleSpecifier"],
"ImportDefaultSpecifier": ["ModuleSpecifier"], "ImportDefaultSpecifier": ["ModuleSpecifier"],
@ -26,12 +28,12 @@
"ExportNamedDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"], "ExportNamedDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
"ImportDeclaration": ["Statement", "Declaration", "ModuleDeclaration"], "ImportDeclaration": ["Statement", "Declaration", "ModuleDeclaration"],
"ArrowFunctionExpression": ["Scopable", "Function", "Func", "Expression", "Pure"], "ArrowFunctionExpression": ["Scopable", "Function", "Func", "BlockParent", "FunctionParent", "Expression", "Pure"],
"FunctionDeclaration": ["Scopable", "Function", "Func", "Statement", "Pure", "Declaration"], "FunctionDeclaration": ["Scopable", "Function", "Func", "BlockParent", "FunctionParent", "Statement", "Pure", "Declaration"],
"FunctionExpression": ["Scopable", "Function", "Func", "Expression", "Pure"], "FunctionExpression": ["Scopable", "Function", "Func", "BlockParent", "FunctionParent", "Expression", "Pure"],
"BlockStatement": ["Scopable", "Statement"], "BlockStatement": ["Scopable", "BlockParent", "Statement"],
"Program": ["Scopable"], "Program": ["Scopable", "BlockParent", "FunctionParent"],
"CatchClause": ["Scopable"], "CatchClause": ["Scopable"],
"LogicalExpression": ["Binary", "Expression"], "LogicalExpression": ["Binary", "Expression"],
@ -44,9 +46,9 @@
"ClassDeclaration": ["Scopable", "Class", "Statement", "Declaration"], "ClassDeclaration": ["Scopable", "Class", "Statement", "Declaration"],
"ClassExpression": ["Scopable", "Class", "Expression"], "ClassExpression": ["Scopable", "Class", "Expression"],
"ForOfStatement": ["Scopable", "Statement", "For", "Loop", "ForXStatement"], "ForOfStatement": ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"],
"ForInStatement": ["Scopable", "Statement", "For", "Loop", "ForXStatement"], "ForInStatement": ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"],
"ForStatement": ["Scopable", "Statement", "For", "Loop"], "ForStatement": ["Scopable", "Statement", "For", "BlockParent", "Loop"],
"ObjectPattern": ["Pattern"], "ObjectPattern": ["Pattern"],
"ArrayPattern": ["Pattern"], "ArrayPattern": ["Pattern"],
@ -54,9 +56,11 @@
"Property": ["UserWhitespacable"], "Property": ["UserWhitespacable"],
"AwaitExpression": ["Expression", "Terminatorless"],
"YieldExpression": ["Expression", "Terminatorless"],
"ArrayExpression": ["Expression"], "ArrayExpression": ["Expression"],
"AssignmentExpression": ["Expression"], "AssignmentExpression": ["Expression"],
"AwaitExpression": ["Expression", "Terminatorless"],
"CallExpression": ["Expression"], "CallExpression": ["Expression"],
"ComprehensionExpression": ["Expression", "Scopable"], "ComprehensionExpression": ["Expression", "Scopable"],
"ConditionalExpression": ["Expression"], "ConditionalExpression": ["Expression"],
@ -74,7 +78,6 @@
"UpdateExpression": ["Expression"], "UpdateExpression": ["Expression"],
"JSXEmptyExpression": ["Expression"], "JSXEmptyExpression": ["Expression"],
"JSXMemberExpression": ["Expression"], "JSXMemberExpression": ["Expression"],
"YieldExpression": ["Expression", "Terminatorless"],
"AnyTypeAnnotation": ["Flow"], "AnyTypeAnnotation": ["Flow"],
"ArrayTypeAnnotation": ["Flow"], "ArrayTypeAnnotation": ["Flow"],