-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
parserRealSource8.2.minified.js
115 lines (115 loc) · 14.1 KB
/
parserRealSource8.2.minified.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//// [parserRealSource8.ts]
// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0.
// See LICENSE.txt in the project root for complete license information.
///<reference path='typescript.ts' />
var TypeScript, TypeScript1, pushAssignScope, popAssignScope, instanceCompare, instanceFilterStop, preAssignModuleScopes, preAssignClassScopes, preAssignInterfaceScopes, preAssignWithScopes, preAssignFuncDeclScopes, preAssignCatchScopes, ScopeSearchFilter;
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
TypeScript1 = TypeScript || (TypeScript = {}), pushAssignScope = function(scope, context, type, classType, fnc) {
var chain = new ScopeChain(null, context.scopeChain, scope);
chain.thisType = type, chain.classType = classType, chain.fnc = fnc, context.scopeChain = chain;
}, popAssignScope = function(context) {
context.scopeChain = context.scopeChain.previous;
}, instanceCompare = function(a, b) {
return null != a && a.isInstanceProperty() ? a : b;
}, instanceFilterStop = function(s) {
return s.isInstanceProperty();
}, preAssignModuleScopes = function(ast, context) {
var memberScope = null, aggScope = null;
ast.name && ast.mod && (ast.name.sym = ast.mod.symbol);
var mod = ast.mod;
// We're likely here because of error recovery
mod && (memberScope = new SymbolTableScope(mod.members, mod.ambientMembers, mod.enclosedTypes, mod.ambientEnclosedTypes, mod.symbol), mod.memberScope = memberScope, context.modDeclChain.push(ast), context.typeFlow.checker.currentModDecl = ast, (aggScope = new SymbolAggregateScope(mod.symbol)).addParentScope(memberScope), aggScope.addParentScope(context.scopeChain.scope), pushAssignScope(aggScope, context, null, null, null), mod.containedScope = aggScope, mod.symbol && context.typeFlow.addLocalsFromScope(mod.containedScope, mod.symbol, ast.vars, mod.members.privateMembers, !0));
}, preAssignClassScopes = function(ast, context) {
var memberScope = null, aggScope = null;
ast.name && ast.type && (ast.name.sym = ast.type.symbol);
var classType = ast.type;
if (classType) {
classType.symbol, memberScope = context.typeFlow.checker.scopeOf(classType), (aggScope = new SymbolAggregateScope(classType.symbol)).addParentScope(memberScope), aggScope.addParentScope(context.scopeChain.scope), classType.containedScope = aggScope, classType.memberScope = memberScope;
var instanceType = classType.instanceType;
memberScope = context.typeFlow.checker.scopeOf(instanceType), instanceType.memberScope = memberScope, (aggScope = new SymbolAggregateScope(instanceType.symbol)).addParentScope(context.scopeChain.scope), pushAssignScope(aggScope, context, instanceType, classType, null), instanceType.containedScope = aggScope;
} else ast.type = context.typeFlow.anyType;
}, preAssignInterfaceScopes = function(ast, context) {
var memberScope = null, aggScope = null;
ast.name && ast.type && (ast.name.sym = ast.type.symbol);
var interfaceType = ast.type;
memberScope = context.typeFlow.checker.scopeOf(interfaceType), interfaceType.memberScope = memberScope, (aggScope = new SymbolAggregateScope(interfaceType.symbol)).addParentScope(memberScope), aggScope.addParentScope(context.scopeChain.scope), pushAssignScope(aggScope, context, null, null, null), interfaceType.containedScope = aggScope;
}, preAssignWithScopes = function(ast, context) {
var withType = ast.type, members = new ScopedMembers(new DualStringHashTable(new StringHashTable(), new StringHashTable())), ambientMembers = new ScopedMembers(new DualStringHashTable(new StringHashTable(), new StringHashTable())), withType = new Type(), withSymbol = new WithSymbol(ast.minChar, context.typeFlow.checker.locationInfo.unitIndex, withType);
withType.members = members, withType.ambientMembers = ambientMembers, withType.symbol = withSymbol, withType.setHasImplementation(), ast.type = withType;
var withScope = new TypeScript.SymbolScopeBuilder(withType.members, withType.ambientMembers, null, null, context.scopeChain.scope, withType.symbol);
pushAssignScope(withScope, context, null, null, null), withType.containedScope = withScope;
}, preAssignFuncDeclScopes = function(ast, context) {
var container = null, localContainer = null;
ast.type && (localContainer = ast.type.symbol);
var isStatic = hasFlag(ast.fncFlags, FncFlags.Static), parentScope = isStatic && null != context.scopeChain.fnc ? context.scopeChain.fnc.type.memberScope : context.scopeChain.scope;
// if this is not a method, but enclosed by class, use constructor as
// the enclosing scope
// REVIEW: Some twisted logic here - this needs to be cleaned up once old classes are removed
// - if it's a new class, always use the contained scope, since we initialize the constructor scope below
if (context.scopeChain.thisType && (!ast.isConstructor || hasFlag(ast.fncFlags, FncFlags.ClassMethod))) {
var instType = context.scopeChain.thisType;
// if the parent is the class constructor, use the constructor scope
parentScope = instType.typeFlags & TypeFlags.IsClass || hasFlag(ast.fncFlags, FncFlags.ClassMethod) ? context.scopeChain.previous.scope.container && context.scopeChain.previous.scope.container.declAST && context.scopeChain.previous.scope.container.declAST.nodeType == NodeType.FuncDecl && context.scopeChain.previous.scope.container.declAST.isConstructor ? instType.constructorScope : isStatic && context.scopeChain.classType ? context.scopeChain.classType.containedScope : instType.containedScope : !ast.isMethod() || isStatic ? instType.constructorScope : instType.containedScope, container = instType.symbol;
} else ast.isConstructor && context.scopeChain.thisType && // sets the container to the class type's symbol (which is shared by the instance type)
(container = context.scopeChain.thisType.symbol);
if (null == ast.type || hasFlag(ast.type.symbol.flags, SymbolFlags.TypeSetDuringScopeAssignment)) {
context.scopeChain.fnc && context.scopeChain.fnc.type && (container = context.scopeChain.fnc.type.symbol);
var funcScope = null, outerFnc = context.scopeChain.fnc, nameText = ast.name ? ast.name.actualText : null, fgSym = null;
isStatic ? (null == outerFnc.type.members && container.getType().memberScope && (outerFnc.type.members = container.type.memberScope.valueMembers), funcScope = context.scopeChain.fnc.type.memberScope, outerFnc.innerStaticFuncs[outerFnc.innerStaticFuncs.length] = ast) : funcScope = !ast.isConstructor && container && container.declAST && container.declAST.nodeType == NodeType.FuncDecl && container.declAST.isConstructor && !ast.isMethod() ? context.scopeChain.thisType.constructorScope : context.scopeChain.scope, nameText && "__missing" != nameText && !ast.isAccessor() && (fgSym = funcScope.findLocal(nameText, !1, !1)), context.typeFlow.checker.createFunctionSignature(ast, container, funcScope, fgSym, null == fgSym), (!ast.accessorSymbol && ast.fncFlags & FncFlags.ClassMethod && container && (!fgSym || fgSym.declAST.nodeType != NodeType.FuncDecl) && ast.isAccessor() || fgSym && fgSym.isAccessor()) && (ast.accessorSymbol = context.typeFlow.checker.createAccessorSymbol(ast, fgSym, container.getType(), ast.isMethod() && isStatic, !0, funcScope, container)), ast.type.symbol.flags |= SymbolFlags.TypeSetDuringScopeAssignment;
}
// Overloads have no scope, so bail here
if (ast.name && ast.type && (ast.name.sym = ast.type.symbol), // Keep track of the original scope type, because target typing might override
// the "type" member. We need the original "Scope type" for completion list, etc.
ast.scopeType = ast.type, !ast.isOverload) {
var funcTable = new StringHashTable(), funcMembers = new ScopedMembers(new DualStringHashTable(funcTable, new StringHashTable())), ambientFuncTable = new StringHashTable(), ambientFuncMembers = new ScopedMembers(new DualStringHashTable(ambientFuncTable, new StringHashTable())), funcStaticTable = new StringHashTable(), funcStaticMembers = new ScopedMembers(new DualStringHashTable(funcStaticTable, new StringHashTable())), ambientFuncStaticTable = new StringHashTable(), ambientFuncStaticMembers = new ScopedMembers(new DualStringHashTable(ambientFuncStaticTable, new StringHashTable()));
// REVIEW: Is it a problem that this is being set twice for properties and constructors?
ast.unitIndex = context.typeFlow.checker.locationInfo.unitIndex;
var locals = new SymbolScopeBuilder(funcMembers, ambientFuncMembers, null, null, parentScope, localContainer), statics = new SymbolScopeBuilder(funcStaticMembers, ambientFuncStaticMembers, null, null, parentScope, null);
if (ast.isConstructor && context.scopeChain.thisType && (context.scopeChain.thisType.constructorScope = locals), // basically, there are two problems
// - Above, for new classes, we were overwriting the constructor scope with the containing scope. This caused constructor params to be
// in scope everywhere
// - Below, we're setting the contained scope table to the same table we were overwriting the constructor scope with, which we need to
// fish lambda params, etc, out (see funcTable below)
//
// A good first approach to solving this would be to change addLocalsFromScope to take a scope instead of a table, and add to the
// constructor scope as appropriate
ast.symbols = funcTable, !ast.isSpecialFn()) {
var group = ast.type, signature = ast.signature;
ast.isConstructor || (group.containedScope = locals, locals.container = group.symbol, group.memberScope = statics, statics.container = group.symbol), ast.enclosingFnc = context.scopeChain.fnc, group.enclosingType = isStatic ? context.scopeChain.classType : context.scopeChain.thisType;
// for mapping when type checking
var fgSym = ast.type.symbol;
if ((ast.fncFlags & FncFlags.Signature) == FncFlags.None && ast.vars && (context.typeFlow.addLocalsFromScope(locals, fgSym, ast.vars, funcTable, !1), context.typeFlow.addLocalsFromScope(statics, fgSym, ast.statics, funcStaticTable, !1)), signature.parameters) for(var len = signature.parameters.length, i = 0; i < len; i++){
var paramSym = signature.parameters[i];
context.typeFlow.checker.resolveTypeLink(locals, paramSym.parameter.typeLink, !0);
}
context.typeFlow.checker.resolveTypeLink(locals, signature.returnType, ast.isSignature());
}
if (!ast.isConstructor || hasFlag(ast.fncFlags, FncFlags.ClassMethod)) {
var thisType = ast.isConstructor && hasFlag(ast.fncFlags, FncFlags.ClassMethod) ? context.scopeChain.thisType : null;
pushAssignScope(locals, context, thisType, null, ast);
}
}
}, preAssignCatchScopes = function(ast, context) {
if (ast.param) {
var catchTable = new ScopedMembers(new DualStringHashTable(new StringHashTable(), new StringHashTable())), catchLocals = new SymbolScopeBuilder(catchTable, null, null, null, context.scopeChain.scope, context.scopeChain.scope.container); // REVIEW: Should we be allocating a public table instead of a private one?
ast.containedScope = catchLocals, pushAssignScope(catchLocals, context, context.scopeChain.thisType, context.scopeChain.classType, context.scopeChain.fnc);
}
}, TypeScript1.AssignScopeContext = function AssignScopeContext(scopeChain, typeFlow, modDeclChain) {
_class_call_check(this, AssignScopeContext), this.scopeChain = scopeChain, this.typeFlow = typeFlow, this.modDeclChain = modDeclChain;
}, TypeScript1.pushAssignScope = pushAssignScope, TypeScript1.popAssignScope = popAssignScope, TypeScript1.instanceCompare = instanceCompare, TypeScript1.instanceFilterStop = instanceFilterStop, ScopeSearchFilter = function() {
function ScopeSearchFilter(select, stop) {
_class_call_check(this, ScopeSearchFilter), this.select = select, this.stop = stop, this.result = null;
}
var _proto = ScopeSearchFilter.prototype;
return _proto.reset = function() {
this.result = null;
}, _proto.update = function(b) {
return this.result = this.select(this.result, b), !!this.result && this.stop(this.result);
}, ScopeSearchFilter;
}(), TypeScript1.ScopeSearchFilter = ScopeSearchFilter, TypeScript1.instanceFilter = new ScopeSearchFilter(instanceCompare, instanceFilterStop), TypeScript1.preAssignModuleScopes = preAssignModuleScopes, TypeScript1.preAssignClassScopes = preAssignClassScopes, TypeScript1.preAssignInterfaceScopes = preAssignInterfaceScopes, TypeScript1.preAssignWithScopes = preAssignWithScopes, TypeScript1.preAssignFuncDeclScopes = preAssignFuncDeclScopes, TypeScript1.preAssignCatchScopes = preAssignCatchScopes, TypeScript1.preAssignScopes = function(ast, parent, walker) {
var context = walker.state, go = !0;
return ast && (ast.nodeType == NodeType.List ? ast.enclosingScope = context.scopeChain.scope : ast.nodeType == NodeType.ModuleDeclaration ? preAssignModuleScopes(ast, context) : ast.nodeType == NodeType.ClassDeclaration ? preAssignClassScopes(ast, context) : ast.nodeType == NodeType.InterfaceDeclaration ? preAssignInterfaceScopes(ast, context) : ast.nodeType == NodeType.With ? preAssignWithScopes(ast, context) : ast.nodeType == NodeType.FuncDecl ? preAssignFuncDeclScopes(ast, context) : ast.nodeType == NodeType.Catch ? preAssignCatchScopes(ast, context) : ast.nodeType == NodeType.TypeRef && (go = !1)), walker.options.goChildren = go, ast;
}, TypeScript1.postAssignScopes = function(ast, parent, walker) {
var context = walker.state, go = !0;
return ast && (ast.nodeType == NodeType.ModuleDeclaration ? (popAssignScope(context), context.modDeclChain.pop(), context.modDeclChain.length >= 1 && (context.typeFlow.checker.currentModDecl = context.modDeclChain[context.modDeclChain.length - 1])) : ast.nodeType == NodeType.ClassDeclaration ? popAssignScope(context) : ast.nodeType == NodeType.InterfaceDeclaration ? popAssignScope(context) : ast.nodeType == NodeType.With ? popAssignScope(context) : ast.nodeType == NodeType.FuncDecl ? (!ast.isConstructor || hasFlag(ast.fncFlags, FncFlags.ClassMethod)) && !ast.isOverload && popAssignScope(context) : ast.nodeType == NodeType.Catch ? ast.param && popAssignScope(context) : go = !1), walker.options.goChildren = go, ast;
};