Skip to content

Commit 73911a3

Browse files
author
Yui T
committed
Merge branch 'master' into fix4686_fixrename
2 parents 95fc3d6 + 710a5be commit 73911a3

78 files changed

Lines changed: 3581 additions & 958 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Jakefile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,8 @@ function lintFileAsync(options, path, cb) {
924924
var lintTargets = compilerSources
925925
.concat(harnessCoreSources)
926926
.concat(serverCoreSources)
927-
.concat(scriptSources);
927+
.concat(scriptSources)
928+
.concat([path.join(servicesDirectory, "services.ts")]);
928929

929930
desc("Runs tslint on the compiler sources");
930931
task("lint", ["build-rules"], function() {

doc/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This directory contains miscellaneous documentation such as the TypeScript language specification and logo.
2+
If you are looking for more introductory material, you might want to take a look at the [TypeScript Handbook](https://github.com/Microsoft/TypeScript-Handbook).
3+
4+
# Spec Contributions
5+
6+
The specification is first authored as a Microsoft Word (docx) file and then generated into Markdown and PDF formats.
7+
Due to the binary format of docx files, and the merging difficulties that may come with it, it is preferred that any suggestions or problems found in the spec should be [filed as issues](https://github.com/Microsoft/TypeScript/issues/new) rather than sent as pull requests.

src/compiler/binder.ts

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,21 @@ namespace ts {
222222
case SyntaxKind.ExportAssignment:
223223
return (<ExportAssignment>node).isExportEquals ? "export=" : "default";
224224
case SyntaxKind.BinaryExpression:
225-
// Binary expression case is for JS module 'module.exports = expr'
226-
return "export=";
225+
switch (getSpecialPropertyAssignmentKind(node)) {
226+
case SpecialPropertyAssignmentKind.ModuleExports:
227+
// module.exports = ...
228+
return "export=";
229+
case SpecialPropertyAssignmentKind.ExportsProperty:
230+
case SpecialPropertyAssignmentKind.ThisProperty:
231+
// exports.x = ... or this.y = ...
232+
return ((node as BinaryExpression).left as PropertyAccessExpression).name.text;
233+
case SpecialPropertyAssignmentKind.PrototypeProperty:
234+
// className.prototype.methodName = ...
235+
return (((node as BinaryExpression).left as PropertyAccessExpression).expression as PropertyAccessExpression).name.text;
236+
}
237+
Debug.fail("Unknown binary declaration kind");
238+
break;
239+
227240
case SyntaxKind.FunctionDeclaration:
228241
case SyntaxKind.ClassDeclaration:
229242
return node.flags & NodeFlags.Default ? "default" : undefined;
@@ -1166,11 +1179,25 @@ namespace ts {
11661179
return checkStrictModeIdentifier(<Identifier>node);
11671180
case SyntaxKind.BinaryExpression:
11681181
if (isInJavaScriptFile(node)) {
1169-
if (isExportsPropertyAssignment(node)) {
1170-
bindExportsPropertyAssignment(<BinaryExpression>node);
1171-
}
1172-
else if (isModuleExportsAssignment(node)) {
1173-
bindModuleExportsAssignment(<BinaryExpression>node);
1182+
const specialKind = getSpecialPropertyAssignmentKind(node);
1183+
switch (specialKind) {
1184+
case SpecialPropertyAssignmentKind.ExportsProperty:
1185+
bindExportsPropertyAssignment(<BinaryExpression>node);
1186+
break;
1187+
case SpecialPropertyAssignmentKind.ModuleExports:
1188+
bindModuleExportsAssignment(<BinaryExpression>node);
1189+
break;
1190+
case SpecialPropertyAssignmentKind.PrototypeProperty:
1191+
bindPrototypePropertyAssignment(<BinaryExpression>node);
1192+
break;
1193+
case SpecialPropertyAssignmentKind.ThisProperty:
1194+
bindThisPropertyAssignment(<BinaryExpression>node);
1195+
break;
1196+
case SpecialPropertyAssignmentKind.None:
1197+
// Nothing to do
1198+
break;
1199+
default:
1200+
Debug.fail("Unknown special property assignment kind");
11741201
}
11751202
}
11761203
return checkStrictModeBinaryExpression(<BinaryExpression>node);
@@ -1351,6 +1378,34 @@ namespace ts {
13511378
bindExportAssignment(node);
13521379
}
13531380

1381+
function bindThisPropertyAssignment(node: BinaryExpression) {
1382+
// Declare a 'member' in case it turns out the container was an ES5 class
1383+
if (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.FunctionDeclaration) {
1384+
container.symbol.members = container.symbol.members || {};
1385+
declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
1386+
}
1387+
}
1388+
1389+
function bindPrototypePropertyAssignment(node: BinaryExpression) {
1390+
// We saw a node of the form 'x.prototype.y = z'. Declare a 'member' y on x if x was a function.
1391+
1392+
// Look up the function in the local scope, since prototype assignments should
1393+
// follow the function declaration
1394+
const classId = <Identifier>(<PropertyAccessExpression>(<PropertyAccessExpression>node.left).expression).expression;
1395+
const funcSymbol = container.locals[classId.text];
1396+
if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function)) {
1397+
return;
1398+
}
1399+
1400+
// Set up the members collection if it doesn't exist already
1401+
if (!funcSymbol.members) {
1402+
funcSymbol.members = {};
1403+
}
1404+
1405+
// Declare the method/property
1406+
declareSymbol(funcSymbol.members, funcSymbol, <PropertyAccessExpression>node.left, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
1407+
}
1408+
13541409
function bindCallExpression(node: CallExpression) {
13551410
// We're only inspecting call expressions to detect CommonJS modules, so we can skip
13561411
// this check if we've already seen the module indicator

0 commit comments

Comments
 (0)