Skip to content

Commit 728252f

Browse files
author
Arthur Ozga
committed
Merge branch 'master' into FixAbsoluteTripleSlashCompletions
2 parents 3ce97af + 4800464 commit 728252f

19 files changed

+323
-41
lines changed

Gulpfile.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ declare module "gulp-typescript" {
1717
stripInternal?: boolean;
1818
types?: string[];
1919
}
20-
interface CompileStream extends NodeJS.ReadWriteStream { } // Either gulp or gulp-typescript has some odd typings which don't reflect reality, making this required
2120
}
2221
import * as insert from "gulp-insert";
2322
import * as sourcemaps from "gulp-sourcemaps";
@@ -169,7 +168,7 @@ for (const i in libraryTargets) {
169168
gulp.task(target, false, [], function() {
170169
return gulp.src(sources)
171170
.pipe(newer(target))
172-
.pipe(concat(target, { newLine: "" }))
171+
.pipe(concat(target, { newLine: "\n\n" }))
173172
.pipe(gulp.dest("."));
174173
});
175174
}
@@ -380,18 +379,18 @@ gulp.task(builtLocalCompiler, false, [servicesFile], () => {
380379
return localCompilerProject.src()
381380
.pipe(newer(builtLocalCompiler))
382381
.pipe(sourcemaps.init())
383-
.pipe(tsc(localCompilerProject))
382+
.pipe(localCompilerProject())
384383
.pipe(prependCopyright())
385384
.pipe(sourcemaps.write("."))
386-
.pipe(gulp.dest(builtLocalDirectory));
385+
.pipe(gulp.dest("."));
387386
});
388387

389388
gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => {
390389
const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/false));
391390
const {js, dts} = servicesProject.src()
392391
.pipe(newer(servicesFile))
393392
.pipe(sourcemaps.init())
394-
.pipe(tsc(servicesProject));
393+
.pipe(servicesProject());
395394
const completedJs = js.pipe(prependCopyright())
396395
.pipe(sourcemaps.write("."));
397396
const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/true))
@@ -409,13 +408,13 @@ gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => {
409408
file.path = nodeDefinitionsFile;
410409
return content + "\r\nexport = ts;";
411410
}))
412-
.pipe(gulp.dest(builtLocalDirectory)),
411+
.pipe(gulp.dest(".")),
413412
completedDts.pipe(clone())
414413
.pipe(insert.transform((content, file) => {
415414
file.path = nodeStandaloneDefinitionsFile;
416415
return content.replace(/declare (namespace|module) ts/g, 'declare module "typescript"');
417416
}))
418-
]).pipe(gulp.dest(builtLocalDirectory));
417+
]).pipe(gulp.dest("."));
419418
});
420419

421420
// cancellationToken.js
@@ -425,7 +424,7 @@ gulp.task(cancellationTokenJs, false, [servicesFile], () => {
425424
return cancellationTokenProject.src()
426425
.pipe(newer(cancellationTokenJs))
427426
.pipe(sourcemaps.init())
428-
.pipe(tsc(cancellationTokenProject))
427+
.pipe(cancellationTokenProject())
429428
.pipe(prependCopyright())
430429
.pipe(sourcemaps.write("."))
431430
.pipe(gulp.dest(builtLocalDirectory));
@@ -438,10 +437,10 @@ gulp.task(typingsInstallerJs, false, [servicesFile], () => {
438437
return cancellationTokenProject.src()
439438
.pipe(newer(typingsInstallerJs))
440439
.pipe(sourcemaps.init())
441-
.pipe(tsc(cancellationTokenProject))
440+
.pipe(cancellationTokenProject())
442441
.pipe(prependCopyright())
443442
.pipe(sourcemaps.write("."))
444-
.pipe(gulp.dest(builtLocalDirectory));
443+
.pipe(gulp.dest("."));
445444
});
446445

447446
const serverFile = path.join(builtLocalDirectory, "tsserver.js");
@@ -451,10 +450,10 @@ gulp.task(serverFile, false, [servicesFile, typingsInstallerJs, cancellationToke
451450
return serverProject.src()
452451
.pipe(newer(serverFile))
453452
.pipe(sourcemaps.init())
454-
.pipe(tsc(serverProject))
453+
.pipe(serverProject())
455454
.pipe(prependCopyright())
456455
.pipe(sourcemaps.write("."))
457-
.pipe(gulp.dest(builtLocalDirectory));
456+
.pipe(gulp.dest("."));
458457
});
459458

460459
const tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js");
@@ -465,14 +464,14 @@ gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => {
465464
const {js, dts}: { js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream } = serverLibraryProject.src()
466465
.pipe(sourcemaps.init())
467466
.pipe(newer(tsserverLibraryFile))
468-
.pipe(tsc(serverLibraryProject));
467+
.pipe(serverLibraryProject());
469468

470469
return merge2([
471470
js.pipe(prependCopyright())
472471
.pipe(sourcemaps.write("."))
473-
.pipe(gulp.dest(builtLocalDirectory)),
472+
.pipe(gulp.dest(".")),
474473
dts.pipe(prependCopyright())
475-
.pipe(gulp.dest(builtLocalDirectory))
474+
.pipe(gulp.dest("."))
476475
]);
477476
});
478477

@@ -544,9 +543,9 @@ gulp.task(run, false, [servicesFile], () => {
544543
return testProject.src()
545544
.pipe(newer(run))
546545
.pipe(sourcemaps.init())
547-
.pipe(tsc(testProject))
546+
.pipe(testProject())
548547
.pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "../../" }))
549-
.pipe(gulp.dest(builtLocalDirectory));
548+
.pipe(gulp.dest("."));
550549
});
551550

552551
const internalTests = "internal/";
@@ -730,7 +729,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo
730729
return testProject.src()
731730
.pipe(newer("built/local/bundle.js"))
732731
.pipe(sourcemaps.init())
733-
.pipe(tsc(testProject))
732+
.pipe(testProject)
734733
.pipe(through2.obj((file, enc, next) => {
735734
const originalMap = file.sourceMap;
736735
const prebundledContent = file.contents.toString();

src/compiler/binder.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,11 @@ namespace ts {
964964
currentFlow = preTryFlow;
965965
bind(node.finallyBlock);
966966
}
967-
currentFlow = finishFlowLabel(postFinallyLabel);
967+
// if try statement has finally block and flow after finally block is unreachable - keep it
968+
// otherwise use whatever flow was accumulated at postFinallyLabel
969+
if (!node.finallyBlock || !(currentFlow.flags & FlowFlags.Unreachable)) {
970+
currentFlow = finishFlowLabel(postFinallyLabel);
971+
}
968972
}
969973

970974
function bindSwitchStatement(node: SwitchStatement): void {

src/compiler/transformers/es6.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ namespace ts {
16891689
assignment = flattenVariableDestructuringToExpression(context, decl, hoistVariableDeclaration, /*nameSubstitution*/ undefined, visitor);
16901690
}
16911691
else {
1692-
assignment = createBinary(<Identifier>decl.name, SyntaxKind.EqualsToken, decl.initializer);
1692+
assignment = createBinary(<Identifier>decl.name, SyntaxKind.EqualsToken, visitNode(decl.initializer, visitor, isExpression));
16931693
}
16941694
(assignments || (assignments = [])).push(assignment);
16951695
}

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ namespace ts.projectSystem {
5151

5252
export class TestTypingsInstaller extends TI.TypingsInstaller implements server.ITypingsInstaller {
5353
protected projectService: server.ProjectService;
54-
constructor(readonly globalTypingsCacheLocation: string, throttleLimit: number, readonly installTypingHost: server.ServerHost) {
55-
super(globalTypingsCacheLocation, "npm", safeList.path, throttleLimit);
54+
constructor(readonly globalTypingsCacheLocation: string, throttleLimit: number, readonly installTypingHost: server.ServerHost, log?: TI.Log) {
55+
super(globalTypingsCacheLocation, "npm", safeList.path, throttleLimit, log);
5656
this.init();
5757
}
5858

src/harness/unittests/typingsInstaller.ts

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ namespace ts.projectSystem {
1111
}
1212

1313
class Installer extends TestTypingsInstaller {
14-
constructor(host: server.ServerHost, p?: InstallerParams) {
14+
constructor(host: server.ServerHost, p?: InstallerParams, log?: TI.Log) {
1515
super(
1616
(p && p.globalTypingsCacheLocation) || "/a/data",
1717
(p && p.throttleLimit) || 5,
18-
host);
18+
host,
19+
log);
1920
}
2021

2122
installAll(expectedView: typeof TI.NpmViewRequest[], expectedInstall: typeof TI.NpmInstallRequest[]) {
@@ -685,10 +686,10 @@ namespace ts.projectSystem {
685686
};
686687
const bowerJson = {
687688
path: "/bower.json",
688-
content: JSON.stringify({
689-
"dependencies": {
690-
"jquery": "^3.1.0"
691-
}
689+
content: JSON.stringify({
690+
"dependencies": {
691+
"jquery": "^3.1.0"
692+
}
692693
})
693694
};
694695
const jqueryDTS = {
@@ -720,4 +721,60 @@ namespace ts.projectSystem {
720721
checkProjectActualFiles(p, [app.path, jqueryDTS.path]);
721722
});
722723
});
724+
725+
describe("Validate package name:", () => {
726+
it ("name cannot be too long", () => {
727+
let packageName = "a";
728+
for (let i = 0; i < 8; i++) {
729+
packageName += packageName;
730+
}
731+
assert.equal(TI.validatePackageName(packageName), TI.PackageNameValidationResult.NameTooLong);
732+
});
733+
it ("name cannot start with dot", () => {
734+
assert.equal(TI.validatePackageName(".foo"), TI.PackageNameValidationResult.NameStartsWithDot);
735+
});
736+
it ("name cannot start with underscore", () => {
737+
assert.equal(TI.validatePackageName("_foo"), TI.PackageNameValidationResult.NameStartsWithUnderscore);
738+
});
739+
it ("scoped packages not supported", () => {
740+
assert.equal(TI.validatePackageName("@scope/bar"), TI.PackageNameValidationResult.ScopedPackagesNotSupported);
741+
});
742+
it ("non URI safe characters are not supported", () => {
743+
assert.equal(TI.validatePackageName(" scope "), TI.PackageNameValidationResult.NameContainsNonURISafeCharacters);
744+
assert.equal(TI.validatePackageName("; say ‘Hello from TypeScript!’ #"), TI.PackageNameValidationResult.NameContainsNonURISafeCharacters);
745+
assert.equal(TI.validatePackageName("a/b/c"), TI.PackageNameValidationResult.NameContainsNonURISafeCharacters);
746+
});
747+
});
748+
749+
describe("Invalid package names", () => {
750+
it ("should not be installed", () => {
751+
const f1 = {
752+
path: "/a/b/app.js",
753+
content: "let x = 1"
754+
};
755+
const packageJson = {
756+
path: "/a/b/package.json",
757+
content: JSON.stringify({
758+
"dependencies": {
759+
"; say ‘Hello from TypeScript!’ #": "0.0.x"
760+
}
761+
})
762+
};
763+
const messages: string[] = [];
764+
const host = createServerHost([f1, packageJson]);
765+
const installer = new (class extends Installer {
766+
constructor() {
767+
super(host, { globalTypingsCacheLocation: "/tmp" }, { isEnabled: () => true, writeLine: msg => messages.push(msg) });
768+
}
769+
runCommand(requestKind: TI.RequestKind, requestId: number, command: string, cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
770+
assert(false, "runCommand should not be invoked");
771+
}
772+
})();
773+
const projectService = createProjectService(host, { typingsInstaller: installer });
774+
projectService.openClientFile(f1.path);
775+
776+
installer.checkPendingCommands([]);
777+
assert.isTrue(messages.indexOf("Package name '; say ‘Hello from TypeScript!’ #' contains non URI safe characters") > 0, "should find package with invalid name");
778+
});
779+
});
723780
}

src/server/cancellationToken/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"removeComments": true,
66
"preserveConstEnums": true,
77
"pretty": true,
8-
"outDir": "../../../built/local",
98
"module": "commonjs",
109
"sourceMap": true,
1110
"stripInternal": true,

src/server/session.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ namespace ts.server {
9393
export const Geterr = "geterr";
9494
export const GeterrForProject = "geterrForProject";
9595
export const Implementation = "implementation";
96+
export const ImplementationFull = "implementation-full";
9697
export const SemanticDiagnosticsSync = "semanticDiagnosticsSync";
9798
export const SyntacticDiagnosticsSync = "syntacticDiagnosticsSync";
9899
export const NavBar = "navbar";
@@ -421,19 +422,24 @@ namespace ts.server {
421422
});
422423
}
423424

424-
private getImplementation(args: protocol.FileLocationRequestArgs): protocol.FileSpan[] {
425+
private getImplementation(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.FileSpan[] | ImplementationLocation[] {
425426
const { file, project } = this.getFileAndProject(args);
426427
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
427428
const position = this.getPosition(args, scriptInfo);
428429
const implementations = project.getLanguageService().getImplementationAtPosition(file, position);
429430
if (!implementations) {
430431
return [];
431432
}
432-
return implementations.map(impl => ({
433-
file: impl.fileName,
434-
start: scriptInfo.positionToLineOffset(impl.textSpan.start),
435-
end: scriptInfo.positionToLineOffset(ts.textSpanEnd(impl.textSpan))
436-
}));
433+
if (simplifiedResult) {
434+
return implementations.map(impl => ({
435+
file: impl.fileName,
436+
start: scriptInfo.positionToLineOffset(impl.textSpan.start),
437+
end: scriptInfo.positionToLineOffset(ts.textSpanEnd(impl.textSpan))
438+
}));
439+
}
440+
else {
441+
return implementations;
442+
}
437443
}
438444

439445
private getOccurrences(args: protocol.FileLocationRequestArgs): protocol.OccurrencesResponseItem[] {
@@ -1329,7 +1335,10 @@ namespace ts.server {
13291335
return this.requiredResponse(this.getTypeDefinition(request.arguments));
13301336
},
13311337
[CommandNames.Implementation]: (request: protocol.Request) => {
1332-
return this.requiredResponse(this.getImplementation(request.arguments));
1338+
return this.requiredResponse(this.getImplementation(request.arguments, /*simplifiedResult*/ true));
1339+
},
1340+
[CommandNames.ImplementationFull]: (request: protocol.Request) => {
1341+
return this.requiredResponse(this.getImplementation(request.arguments, /*simplifiedResult*/ false));
13331342
},
13341343
[CommandNames.References]: (request: protocol.FileLocationRequest) => {
13351344
return this.requiredResponse(this.getReferences(request.arguments, /*simplifiedResult*/ true));

src/server/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"removeComments": true,
66
"preserveConstEnums": true,
77
"pretty": true,
8-
"out": "../../built/local/tsserver.js",
8+
"outFile": "../../built/local/tsserver.js",
99
"sourceMap": true,
1010
"stripInternal": true,
1111
"types": [

src/server/tsconfig.library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"noImplicitAny": true,
44
"removeComments": true,
55
"preserveConstEnums": true,
6-
"out": "../../built/local/tsserverlibrary.js",
6+
"outFile": "../../built/local/tsserverlibrary.js",
77
"sourceMap": true,
88
"stripInternal": true,
99
"declaration": true,

src/server/typingsInstaller/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"removeComments": true,
66
"preserveConstEnums": true,
77
"pretty": true,
8-
"out": "../../built/local/typingsInstaller.js",
8+
"outFile": "../../../built/local/typingsInstaller.js",
99
"sourceMap": true,
1010
"stripInternal": true,
1111
"types": [

0 commit comments

Comments
 (0)