Skip to content

Commit 6bd1da2

Browse files
authored
Rename JS-specific concepts (microsoft#26795)
* Rename JS concepts 1. Assignment declaration -- an assignment that is treated like a declaration. Previously called [JS] special (assignment|declaration), among other things. 2. Expando -- a value that can be used as a target in assignment declarations. Currently, a class, function or empty object literal. Functions are allowed in Typescript, too. Previously called a JS container, JS initializer or expando object. 3. JavaScript -> Javascript. This is annoying to type, and looks like 'Java Script' in a camelCase world. Everything is a pure rename as far as I know. The only test change is the API baselines, which reflect the rename from SymbolFlags.JSContainer to SymbolFlags.Assignment. * Remove TODO * Rename Javascript->JS Note that this introduces a variable name collision in a couple of places, which I resolved like this: ```ts const isInJavascript = isInJSFile(node); ```
1 parent 371ffff commit 6bd1da2

36 files changed

+331
-331
lines changed

src/compiler/binder.ts

+26-26
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ namespace ts {
288288
// module.exports = ...
289289
return InternalSymbolName.ExportEquals;
290290
case SyntaxKind.BinaryExpression:
291-
if (getSpecialPropertyAssignmentKind(node as BinaryExpression) === SpecialPropertyAssignmentKind.ModuleExports) {
291+
if (getAssignmentDeclarationKind(node as BinaryExpression) === AssignmentDeclarationKind.ModuleExports) {
292292
// module.exports = ...
293293
return InternalSymbolName.ExportEquals;
294294
}
@@ -374,8 +374,8 @@ namespace ts {
374374
// prototype symbols like methods.
375375
symbolTable.set(name, symbol = createSymbol(SymbolFlags.None, name));
376376
}
377-
else if (!(includes & SymbolFlags.Variable && symbol.flags & SymbolFlags.JSContainer)) {
378-
// JSContainers are allowed to merge with variables, no matter what other flags they have.
377+
else if (!(includes & SymbolFlags.Variable && symbol.flags & SymbolFlags.Assignment)) {
378+
// Assignment declarations are allowed to merge with variables, no matter what other flags they have.
379379
if (isNamedDeclaration(node)) {
380380
node.name.parent = node;
381381
}
@@ -461,7 +461,7 @@ namespace ts {
461461
// during global merging in the checker. Why? The only case when ambient module is permitted inside another module is module augmentation
462462
// and this case is specially handled. Module augmentations should only be merged with original module definition
463463
// and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed.
464-
if (isJSDocTypeAlias(node)) Debug.assert(isInJavaScriptFile(node)); // We shouldn't add symbols for JSDoc nodes if not in a JS file.
464+
if (isJSDocTypeAlias(node)) Debug.assert(isInJSFile(node)); // We shouldn't add symbols for JSDoc nodes if not in a JS file.
465465
if ((!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) || isJSDocTypeAlias(node)) {
466466
if (hasModifier(node, ModifierFlags.Default) && !getDeclarationName(node)) {
467467
return declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes); // No local symbol for an unnamed default!
@@ -2009,7 +2009,7 @@ namespace ts {
20092009

20102010
function bindJSDoc(node: Node) {
20112011
if (hasJSDocNodes(node)) {
2012-
if (isInJavaScriptFile(node)) {
2012+
if (isInJSFile(node)) {
20132013
for (const j of node.jsDoc!) {
20142014
bind(j);
20152015
}
@@ -2075,7 +2075,7 @@ namespace ts {
20752075
if (isSpecialPropertyDeclaration(node as PropertyAccessExpression)) {
20762076
bindSpecialPropertyDeclaration(node as PropertyAccessExpression);
20772077
}
2078-
if (isInJavaScriptFile(node) &&
2078+
if (isInJSFile(node) &&
20792079
file.commonJsModuleIndicator &&
20802080
isModuleExportsPropertyAccessExpression(node as PropertyAccessExpression) &&
20812081
!lookupSymbolForNameWorker(blockScopeContainer, "module" as __String)) {
@@ -2084,27 +2084,27 @@ namespace ts {
20842084
}
20852085
break;
20862086
case SyntaxKind.BinaryExpression:
2087-
const specialKind = getSpecialPropertyAssignmentKind(node as BinaryExpression);
2087+
const specialKind = getAssignmentDeclarationKind(node as BinaryExpression);
20882088
switch (specialKind) {
2089-
case SpecialPropertyAssignmentKind.ExportsProperty:
2089+
case AssignmentDeclarationKind.ExportsProperty:
20902090
bindExportsPropertyAssignment(node as BinaryExpression);
20912091
break;
2092-
case SpecialPropertyAssignmentKind.ModuleExports:
2092+
case AssignmentDeclarationKind.ModuleExports:
20932093
bindModuleExportsAssignment(node as BinaryExpression);
20942094
break;
2095-
case SpecialPropertyAssignmentKind.PrototypeProperty:
2095+
case AssignmentDeclarationKind.PrototypeProperty:
20962096
bindPrototypePropertyAssignment((node as BinaryExpression).left as PropertyAccessEntityNameExpression, node);
20972097
break;
2098-
case SpecialPropertyAssignmentKind.Prototype:
2098+
case AssignmentDeclarationKind.Prototype:
20992099
bindPrototypeAssignment(node as BinaryExpression);
21002100
break;
2101-
case SpecialPropertyAssignmentKind.ThisProperty:
2101+
case AssignmentDeclarationKind.ThisProperty:
21022102
bindThisPropertyAssignment(node as BinaryExpression);
21032103
break;
2104-
case SpecialPropertyAssignmentKind.Property:
2104+
case AssignmentDeclarationKind.Property:
21052105
bindSpecialPropertyAssignment(node as BinaryExpression);
21062106
break;
2107-
case SpecialPropertyAssignmentKind.None:
2107+
case AssignmentDeclarationKind.None:
21082108
// Nothing to do
21092109
break;
21102110
default:
@@ -2184,7 +2184,7 @@ namespace ts {
21842184
return bindFunctionExpression(<FunctionExpression>node);
21852185

21862186
case SyntaxKind.CallExpression:
2187-
if (isInJavaScriptFile(node)) {
2187+
if (isInJSFile(node)) {
21882188
bindCallExpression(<CallExpression>node);
21892189
}
21902190
break;
@@ -2361,7 +2361,7 @@ namespace ts {
23612361
const lhs = node.left as PropertyAccessEntityNameExpression;
23622362
const symbol = forEachIdentifierInEntityName(lhs.expression, /*parent*/ undefined, (id, symbol) => {
23632363
if (symbol) {
2364-
addDeclarationToSymbol(symbol, id, SymbolFlags.Module | SymbolFlags.JSContainer);
2364+
addDeclarationToSymbol(symbol, id, SymbolFlags.Module | SymbolFlags.Assignment);
23652365
}
23662366
return symbol;
23672367
});
@@ -2394,7 +2394,7 @@ namespace ts {
23942394
}
23952395

23962396
function bindThisPropertyAssignment(node: BinaryExpression | PropertyAccessExpression) {
2397-
Debug.assert(isInJavaScriptFile(node));
2397+
Debug.assert(isInJSFile(node));
23982398
const thisContainer = getThisContainer(node, /*includeArrowFunctions*/ false);
23992399
switch (thisContainer.kind) {
24002400
case SyntaxKind.FunctionDeclaration:
@@ -2482,7 +2482,7 @@ namespace ts {
24822482
const lhs = node.left as PropertyAccessEntityNameExpression;
24832483
// Class declarations in Typescript do not allow property declarations
24842484
const parentSymbol = lookupSymbolForPropertyAccess(lhs.expression);
2485-
if (!isInJavaScriptFile(node) && !isFunctionSymbol(parentSymbol)) {
2485+
if (!isInJSFile(node) && !isFunctionSymbol(parentSymbol)) {
24862486
return;
24872487
}
24882488
// Fix up parent pointers since we're going to use these nodes before we bind into them
@@ -2515,8 +2515,8 @@ namespace ts {
25152515
: propertyAccess.parent.parent.kind === SyntaxKind.SourceFile;
25162516
if (!isPrototypeProperty && (!namespaceSymbol || !(namespaceSymbol.flags & SymbolFlags.Namespace)) && isToplevel) {
25172517
// make symbols or add declarations for intermediate containers
2518-
const flags = SymbolFlags.Module | SymbolFlags.JSContainer;
2519-
const excludeFlags = SymbolFlags.ValueModuleExcludes & ~SymbolFlags.JSContainer;
2518+
const flags = SymbolFlags.Module | SymbolFlags.Assignment;
2519+
const excludeFlags = SymbolFlags.ValueModuleExcludes & ~SymbolFlags.Assignment;
25202520
namespaceSymbol = forEachIdentifierInEntityName(propertyAccess.expression, namespaceSymbol, (id, symbol, parent) => {
25212521
if (symbol) {
25222522
addDeclarationToSymbol(symbol, id, flags);
@@ -2527,7 +2527,7 @@ namespace ts {
25272527
}
25282528
});
25292529
}
2530-
if (!namespaceSymbol || !isJavascriptContainer(namespaceSymbol)) {
2530+
if (!namespaceSymbol || !isExpandoSymbol(namespaceSymbol)) {
25312531
return;
25322532
}
25332533

@@ -2536,14 +2536,14 @@ namespace ts {
25362536
(namespaceSymbol.members || (namespaceSymbol.members = createSymbolTable())) :
25372537
(namespaceSymbol.exports || (namespaceSymbol.exports = createSymbolTable()));
25382538

2539-
const isMethod = isFunctionLikeDeclaration(getAssignedJavascriptInitializer(propertyAccess)!);
2539+
const isMethod = isFunctionLikeDeclaration(getAssignedExpandoInitializer(propertyAccess)!);
25402540
const includes = isMethod ? SymbolFlags.Method : SymbolFlags.Property;
25412541
const excludes = isMethod ? SymbolFlags.MethodExcludes : SymbolFlags.PropertyExcludes;
2542-
declareSymbol(symbolTable, namespaceSymbol, propertyAccess, includes | SymbolFlags.JSContainer, excludes & ~SymbolFlags.JSContainer);
2542+
declareSymbol(symbolTable, namespaceSymbol, propertyAccess, includes | SymbolFlags.Assignment, excludes & ~SymbolFlags.Assignment);
25432543
}
25442544

25452545
/**
2546-
* Javascript containers are:
2546+
* Javascript expando values are:
25472547
* - Functions
25482548
* - classes
25492549
* - namespaces
@@ -2552,7 +2552,7 @@ namespace ts {
25522552
* - with empty object literals
25532553
* - with non-empty object literals if assigned to the prototype property
25542554
*/
2555-
function isJavascriptContainer(symbol: Symbol): boolean {
2555+
function isExpandoSymbol(symbol: Symbol): boolean {
25562556
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.NamespaceModule)) {
25572557
return true;
25582558
}
@@ -2565,7 +2565,7 @@ namespace ts {
25652565
init = init && getRightMostAssignedExpression(init);
25662566
if (init) {
25672567
const isPrototypeAssignment = isPrototypeAccess(isVariableDeclaration(node) ? node.name : isBinaryExpression(node) ? node.left : node);
2568-
return !!getJavascriptInitializer(isBinaryExpression(init) && init.operatorToken.kind === SyntaxKind.BarBarToken ? init.right : init, isPrototypeAssignment);
2568+
return !!getExpandoInitializer(isBinaryExpression(init) && init.operatorToken.kind === SyntaxKind.BarBarToken ? init.right : init, isPrototypeAssignment);
25692569
}
25702570
return false;
25712571
}

0 commit comments

Comments
 (0)