Skip to content

Commit 80ff139

Browse files
committed
Merge branch 'master' into taggedTemplates
2 parents ac8e395 + 42bc64b commit 80ff139

File tree

202 files changed

+1800
-450
lines changed

Some content is hidden

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

202 files changed

+1800
-450
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10287,11 +10287,12 @@ module ts {
1028710287

1028810288
case SyntaxKind.StringLiteral:
1028910289
// External module name in an import declaration
10290-
if (isExternalModuleImportEqualsDeclaration(node.parent.parent) &&
10291-
getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) {
10292-
var importSymbol = getSymbolOfNode(node.parent.parent);
10293-
var moduleType = getTypeOfSymbol(importSymbol);
10294-
return moduleType ? moduleType.symbol : undefined;
10290+
var moduleName: Expression;
10291+
if ((isExternalModuleImportEqualsDeclaration(node.parent.parent) &&
10292+
getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) ||
10293+
((node.parent.kind === SyntaxKind.ImportDeclaration || node.parent.kind === SyntaxKind.ExportDeclaration) &&
10294+
(<ImportDeclaration>node.parent).moduleSpecifier === node)) {
10295+
return resolveExternalModuleName(node, <LiteralExpression>node);
1029510296
}
1029610297

1029710298
// Intentional fall-through

src/compiler/core.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ module ts {
607607
}
608608

609609
var backslashOrDoubleQuote = /[\"\\]/g;
610-
var escapedCharsRegExp = /[\0-\19\t\v\f\b\0\r\n\u2028\u2029\u0085]/g;
610+
var escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
611611
var escapedCharsMap: Map<string> = {
612612
"\0": "\\0",
613613
"\t": "\\t",
@@ -624,7 +624,7 @@ module ts {
624624
};
625625

626626
/**
627-
* Based heavily on the abstract 'Quote' operation from ECMA-262 (24.3.2.2),
627+
* Based heavily on the abstract 'Quote'/ 'QuoteJSONString' operation from ECMA-262 (24.3.2.2),
628628
* but augmented for a few select characters.
629629
* Note that this doesn't actually wrap the input in double quotes.
630630
*/

src/compiler/emitter.ts

Lines changed: 10 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -3160,71 +3160,21 @@ module ts {
31603160

31613161
write(tokenToString(node.operatorToken.kind));
31623162

3163-
// We'd like to preserve newlines found in the original binary expression. i.e. if a user has:
3164-
//
3165-
// Foo() ||
3166-
// Bar();
3167-
//
3168-
// Then we'd like to emit it as such. It seems like we'd only need to check for a newline and
3169-
// then just indent and emit. However, that will lead to a problem with deeply nested code.
3170-
// i.e. if you have:
3171-
//
3172-
// Foo() ||
3173-
// Bar() ||
3174-
// Baz();
3175-
//
3176-
// Then we don't want to emit it as:
3177-
//
3178-
// Foo() ||
3179-
// Bar() ||
3180-
// Baz();
3181-
//
3182-
// So we only indent if the right side of the binary expression starts further in on the line
3183-
// versus the left.
3184-
var operatorEnd = getLineAndCharacterOfPosition(currentSourceFile, node.operatorToken.end);
3185-
var rightStart = getLineAndCharacterOfPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node.right.pos));
3186-
31873163
// Check if the right expression is on a different line versus the operator itself. If so,
31883164
// we'll emit newline.
3189-
var onDifferentLine = operatorEnd.line !== rightStart.line;
3190-
if (onDifferentLine) {
3191-
// Also, if the right expression starts further in on the line than the left, then we'll indent.
3192-
var exprStart = getLineAndCharacterOfPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node.pos));
3193-
var firstCharOfExpr = getFirstNonWhitespaceCharacterIndexOnLine(exprStart.line);
3194-
var shouldIndent = rightStart.character > firstCharOfExpr;
3195-
3196-
if (shouldIndent) {
3197-
increaseIndent();
3198-
}
3199-
3165+
if (!nodeEndIsOnSameLineAsNodeStart(node.operatorToken, node.right)) {
3166+
increaseIndent();
32003167
writeLine();
3168+
emit(node.right);
3169+
decreaseIndent();
32013170
}
32023171
else {
32033172
write(" ");
3204-
}
3205-
3206-
emit(node.right);
3207-
3208-
if (shouldIndent) {
3209-
decreaseIndent();
3173+
emit(node.right);
32103174
}
32113175
}
32123176
}
32133177

3214-
function getFirstNonWhitespaceCharacterIndexOnLine(line: number): number {
3215-
var lineStart = getLineStarts(currentSourceFile)[line];
3216-
var text = currentSourceFile.text;
3217-
3218-
for (var i = lineStart; i < text.length; i++) {
3219-
var ch = text.charCodeAt(i);
3220-
if (!isWhiteSpace(text.charCodeAt(i)) || isLineBreak(ch)) {
3221-
break;
3222-
}
3223-
}
3224-
3225-
return i - lineStart;
3226-
}
3227-
32283178
function emitConditionalExpression(node: ConditionalExpression) {
32293179
emit(node.condition);
32303180
write(" ? ");
@@ -4064,58 +4014,21 @@ module ts {
40644014
}
40654015

40664016
function emitBlockFunctionBody(node: FunctionLikeDeclaration, body: Block) {
4067-
// If the body has no statements, and we know there's no code that would cause any
4068-
// prologue to be emitted, then just do a simple emit if the empty block.
4069-
if (body.statements.length === 0 && !anyParameterHasBindingPatternOrInitializer(node)) {
4070-
emitFunctionBodyWithNoStatements(node, body);
4071-
}
4072-
else {
4073-
emitFunctionBodyWithStatements(node, body);
4074-
}
4075-
}
4076-
4077-
function anyParameterHasBindingPatternOrInitializer(func: FunctionLikeDeclaration) {
4078-
return forEach(func.parameters, hasBindingPatternOrInitializer);
4079-
}
4080-
4081-
function hasBindingPatternOrInitializer(parameter: ParameterDeclaration) {
4082-
return parameter.initializer || isBindingPattern(parameter.name);
4083-
}
4084-
4085-
function emitFunctionBodyWithNoStatements(node: FunctionLikeDeclaration, body: Block) {
4086-
var singleLine = isSingleLineEmptyBlock(node.body);
4087-
4088-
write(" {");
4089-
if (singleLine) {
4090-
write(" ");
4091-
}
4092-
else {
4093-
increaseIndent();
4094-
writeLine();
4095-
}
4096-
4097-
emitLeadingCommentsOfPosition(body.statements.end);
4098-
4099-
if (!singleLine) {
4100-
decreaseIndent();
4101-
}
4102-
4103-
emitToken(SyntaxKind.CloseBraceToken, body.statements.end);
4104-
}
4105-
4106-
function emitFunctionBodyWithStatements(node: FunctionLikeDeclaration, body: Block) {
41074017
write(" {");
41084018
scopeEmitStart(node);
41094019

4110-
var outPos = writer.getTextPos();
4020+
var initialTextPos = writer.getTextPos();
41114021

41124022
increaseIndent();
41134023
emitDetachedComments(body.statements);
4024+
4025+
// Emit all the directive prologues (like "use strict"). These have to come before
4026+
// any other preamble code we write (like parameter initializers).
41144027
var startIndex = emitDirectivePrologues(body.statements, /*startWithNewLine*/ true);
41154028
emitFunctionBodyPreamble(node);
41164029
decreaseIndent();
41174030

4118-
var preambleEmitted = writer.getTextPos() !== outPos;
4031+
var preambleEmitted = writer.getTextPos() !== initialTextPos;
41194032

41204033
if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) {
41214034
for (var i = 0, n = body.statements.length; i < n; i++) {

src/compiler/program.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,15 @@ module ts {
177177
return { diagnostics: [], sourceMaps: undefined, emitSkipped: true };
178178
}
179179

180+
// Create the emit resolver outside of the "emitTime" tracking code below. That way
181+
// any cost associated with it (like type checking) are appropriate associated with
182+
// the type-checking counter.
183+
var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile);
184+
180185
var start = new Date().getTime();
181186

182187
var emitResult = emitFiles(
183-
getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile),
188+
emitResolver,
184189
getEmitHost(writeFileCallback),
185190
sourceFile);
186191

src/compiler/utilities.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,12 @@ module ts {
745745
}
746746

747747
var parent = name.parent;
748+
if (parent.kind === SyntaxKind.ImportSpecifier || parent.kind === SyntaxKind.ExportSpecifier) {
749+
if ((<ImportOrExportSpecifier>parent).propertyName) {
750+
return true;
751+
}
752+
}
753+
748754
if (isDeclaration(parent) || parent.kind === SyntaxKind.FunctionExpression) {
749755
return (<Declaration>parent).name === name;
750756
}

src/server/editorServices.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,7 @@ module ts.server {
101101
}
102102

103103
getScriptFileNames() {
104-
var filenames: string[] = [];
105-
for (var filename in this.filenameToScript) {
106-
if (this.filenameToScript[filename] && this.filenameToScript[filename].isOpen) {
107-
filenames.push(filename);
108-
}
109-
}
110-
return filenames;
104+
return this.roots.map(root => root.fileName);
111105
}
112106

113107
getScriptVersion(filename: string) {
@@ -536,15 +530,35 @@ module ts.server {
536530
updateProjectStructure() {
537531
this.log("updating project structure from ...", "Info");
538532
this.printProjects();
533+
534+
// First loop through all open files that are referenced by projects but are not
535+
// project roots. For each referenced file, see if the default project still
536+
// references that file. If so, then just keep the file in the referenced list.
537+
// If not, add the file to an unattached list, to be rechecked later.
538+
539+
var openFilesReferenced: ScriptInfo[] = [];
540+
var unattachedOpenFiles: ScriptInfo[] = [];
541+
539542
for (var i = 0, len = this.openFilesReferenced.length; i < len; i++) {
540-
var refdFile = this.openFilesReferenced[i];
541-
refdFile.defaultProject.updateGraph();
542-
var sourceFile = refdFile.defaultProject.getSourceFile(refdFile);
543-
if (!sourceFile) {
544-
this.openFilesReferenced = copyListRemovingItem(refdFile, this.openFilesReferenced);
545-
this.addOpenFile(refdFile);
543+
var referencedFile = this.openFilesReferenced[i];
544+
referencedFile.defaultProject.updateGraph();
545+
var sourceFile = referencedFile.defaultProject.getSourceFile(referencedFile);
546+
if (sourceFile) {
547+
openFilesReferenced.push(referencedFile);
548+
}
549+
else {
550+
unattachedOpenFiles.push(referencedFile);
546551
}
547552
}
553+
this.openFilesReferenced = openFilesReferenced;
554+
555+
// Then, loop through all of the open files that are project roots.
556+
// For each root file, note the project that it roots. Then see if
557+
// any other projects newly reference the file. If zero projects
558+
// newly reference the file, keep it as a root. If one or more
559+
// projects newly references the file, remove its project from the
560+
// inferred projects list (since it is no longer a root) and add
561+
// the file to the open, referenced file list.
548562
var openFileRoots: ScriptInfo[] = [];
549563
for (var i = 0, len = this.openFileRoots.length; i < len; i++) {
550564
var rootFile = this.openFileRoots[i];
@@ -555,12 +569,19 @@ module ts.server {
555569
openFileRoots.push(rootFile);
556570
}
557571
else {
558-
// remove project from inferred projects list
572+
// remove project from inferred projects list because root captured
559573
this.inferredProjects = copyListRemovingItem(rootedProject, this.inferredProjects);
560574
this.openFilesReferenced.push(rootFile);
561575
}
562576
}
563577
this.openFileRoots = openFileRoots;
578+
579+
// Finally, if we found any open, referenced files that are no longer
580+
// referenced by their default project, treat them as newly opened
581+
// by the editor.
582+
for (var i = 0, len = unattachedOpenFiles.length; i < len; i++) {
583+
this.addOpenFile(unattachedOpenFiles[i]);
584+
}
564585
this.printProjects();
565586
}
566587

src/server/server.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ module ts.server {
206206
}
207207

208208
};
209-
209+
var ioSession = new IOSession(ts.sys, logger);
210+
process.on('uncaughtException', function(err: Error) {
211+
ioSession.logError(err, "unknown");
212+
});
210213
// Start listening
211-
new IOSession(ts.sys, logger).listen();
214+
ioSession.listen();
212215
}

src/server/session.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,29 @@ module ts.server {
181181
}
182182

183183
semanticCheck(file: string, project: Project) {
184-
var diags = project.compilerService.languageService.getSemanticDiagnostics(file);
185-
if (diags) {
186-
var bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
187-
this.event({ file: file, diagnostics: bakedDiags }, "semanticDiag");
184+
try {
185+
var diags = project.compilerService.languageService.getSemanticDiagnostics(file);
186+
187+
if (diags) {
188+
var bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
189+
this.event({ file: file, diagnostics: bakedDiags }, "semanticDiag");
190+
}
191+
}
192+
catch (err) {
193+
this.logError(err, "semantic check");
188194
}
189195
}
190196

191197
syntacticCheck(file: string, project: Project) {
192-
var diags = project.compilerService.languageService.getSyntacticDiagnostics(file);
193-
if (diags) {
194-
var bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
195-
this.event({ file: file, diagnostics: bakedDiags }, "syntaxDiag");
198+
try {
199+
var diags = project.compilerService.languageService.getSyntacticDiagnostics(file);
200+
if (diags) {
201+
var bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
202+
this.event({ file: file, diagnostics: bakedDiags }, "syntaxDiag");
203+
}
204+
}
205+
catch (err) {
206+
this.logError(err, "syntactic check");
196207
}
197208
}
198209

@@ -553,10 +564,7 @@ module ts.server {
553564
compilerService.host.editScript(file, start, end, insertString);
554565
this.changeSeq++;
555566
}
556-
// update project structure on idle commented out
557-
// until we can have the host return only the root files
558-
// from getScriptFileNames()
559-
//this.updateProjectStructure(this.changeSeq, (n) => n == this.changeSeq);
567+
this.updateProjectStructure(this.changeSeq, (n) => n == this.changeSeq);
560568
}
561569
}
562570

src/services/breakpoints.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,15 @@ module ts.BreakpointResolver {
178178

179179
case SyntaxKind.ImportEqualsDeclaration:
180180
// import statement without including semicolon
181-
return textSpan(node,(<ImportEqualsDeclaration>node).moduleReference);
181+
return textSpan(node, (<ImportEqualsDeclaration>node).moduleReference);
182+
183+
case SyntaxKind.ImportDeclaration:
184+
// import statement without including semicolon
185+
return textSpan(node, (<ImportDeclaration>node).moduleSpecifier);
186+
187+
case SyntaxKind.ExportDeclaration:
188+
// import statement without including semicolon
189+
return textSpan(node, (<ExportDeclaration>node).moduleSpecifier);
182190

183191
case SyntaxKind.ModuleDeclaration:
184192
// span on complete module if it is instantiated

0 commit comments

Comments
 (0)