Change static fields emits (#43114)

* use emit into iife

* Update emit

* Revert un-related changes

* Allow super in static context

* Allow this and super in static property declaration

* Add more tests

* Avoid errors

* Accept baseline

* Accept baseline

* Add decorated classes test

* Add errors

* Avoid this in emitter

* make lint happy

* Add class expression tests

* Add computed name test

* Avoid super if target below es6

* Adjust function boundary

* Add internal

* Fix minor CR issues

* accept baseline

* Update behavior

* Avoid spaces

* Make lint happy

* Avoid function boundary utils

* Update baseline

* Avoid errors

* Accept baseline

* Accept baseline

* Accept baseline

* Accept baseline

* Use substitutions

* Full coverage for super, this, merge static and private context

* Fix use-before-def in static fields

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
This commit is contained in:
Wenlu Wang
2021-06-25 15:49:27 -07:00
committed by GitHub
co-authored by Ron Buckton
parent 328e888a9d
commit dc237b317e
215 changed files with 9185 additions and 782 deletions
+4 -1
View File
@@ -2313,6 +2313,9 @@ namespace ts.Completions {
break;
}
}
if (isClassStaticBlockDeclaration(classElement)) {
classElementModifierFlags |= ModifierFlags.Static;
}
// No member list for private methods
if (!(classElementModifierFlags & ModifierFlags.Private)) {
@@ -2766,7 +2769,7 @@ namespace ts.Completions {
}
// do not filter it out if the static presence doesnt match
if (hasEffectiveModifier(m, ModifierFlags.Static) !== !!(currentClassElementModifierFlags & ModifierFlags.Static)) {
if (isStatic(m) !== !!(currentClassElementModifierFlags & ModifierFlags.Static)) {
continue;
}
+6 -6
View File
@@ -1684,7 +1684,7 @@ namespace ts.FindAllReferences {
Debug.assert(classLike.name === referenceLocation);
const addRef = state.referenceAdder(search.symbol);
for (const member of classLike.members) {
if (!(isMethodOrAccessor(member) && hasSyntacticModifier(member, ModifierFlags.Static))) {
if (!(isMethodOrAccessor(member) && isStatic(member))) {
continue;
}
if (member.body) {
@@ -1917,7 +1917,7 @@ namespace ts.FindAllReferences {
// If we have a 'super' container, we must have an enclosing class.
// Now make sure the owning class is the same as the search-space
// and has the same static qualifier as the original 'super's owner.
return container && (ModifierFlags.Static & getSyntacticModifierFlags(container)) === staticFlag && container.parent.symbol === searchSpaceNode.symbol ? nodeEntry(node) : undefined;
return container && isStatic(container) === !!staticFlag && container.parent.symbol === searchSpaceNode.symbol ? nodeEntry(node) : undefined;
});
return [{ definition: { type: DefinitionKind.Symbol, symbol: searchSpaceNode.symbol }, references }];
@@ -1983,7 +1983,7 @@ namespace ts.FindAllReferences {
case SyntaxKind.ObjectLiteralExpression:
// Make sure the container belongs to the same class/object literals
// and has the appropriate static modifier from the original container.
return container.parent && searchSpaceNode.symbol === container.parent.symbol && (getSyntacticModifierFlags(container) & ModifierFlags.Static) === staticFlag;
return container.parent && searchSpaceNode.symbol === container.parent.symbol && isStatic(container) === !!staticFlag;
case SyntaxKind.SourceFile:
return container.kind === SyntaxKind.SourceFile && !isExternalModule(container as SourceFile) && !isParameterName(node);
}
@@ -2030,7 +2030,7 @@ namespace ts.FindAllReferences {
(sym, root, base) => {
// static method/property and instance method/property might have the same name. Only include static or only include instance.
if (base) {
if (isStatic(symbol) !== isStatic(base)) {
if (isStaticSymbol(symbol) !== isStaticSymbol(base)) {
base = undefined;
}
}
@@ -2196,7 +2196,7 @@ namespace ts.FindAllReferences {
readonly kind: NodeEntryKind | undefined;
}
function isStatic(symbol: Symbol): boolean {
function isStaticSymbol(symbol: Symbol): boolean {
if (!symbol.valueDeclaration) { return false; }
const modifierFlags = getEffectiveModifierFlags(symbol.valueDeclaration);
return !!(modifierFlags & ModifierFlags.Static);
@@ -2210,7 +2210,7 @@ namespace ts.FindAllReferences {
// check whether the symbol used to search itself is just the searched one.
if (baseSymbol) {
// static method/property and instance method/property might have the same name. Only check static or only check instance.
if (isStatic(referenceSymbol) !== isStatic(baseSymbol)) {
if (isStaticSymbol(referenceSymbol) !== isStaticSymbol(baseSymbol)) {
baseSymbol = undefined;
}
}
+1 -1
View File
@@ -627,7 +627,7 @@ namespace ts.NavigationBar {
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return hasSyntacticModifier(a, ModifierFlags.Static) === hasSyntacticModifier(b, ModifierFlags.Static);
return isStatic(a) === isStatic(b);
case SyntaxKind.ModuleDeclaration:
return areSameModule(a as ModuleDeclaration, b as ModuleDeclaration)
&& getFullyQualifiedModuleName(a as ModuleDeclaration) === getFullyQualifiedModuleName(b as ModuleDeclaration);
+2 -2
View File
@@ -398,7 +398,7 @@ namespace ts.refactor.extractSymbol {
let current: Node = nodeToCheck;
while (current !== containingClass) {
if (current.kind === SyntaxKind.PropertyDeclaration) {
if (hasSyntacticModifier(current, ModifierFlags.Static)) {
if (isStatic(current)) {
rangeFacts |= RangeFacts.InStaticRegion;
}
break;
@@ -411,7 +411,7 @@ namespace ts.refactor.extractSymbol {
break;
}
else if (current.kind === SyntaxKind.MethodDeclaration) {
if (hasSyntacticModifier(current, ModifierFlags.Static)) {
if (isStatic(current)) {
rangeFacts |= RangeFacts.InStaticRegion;
}
}