Skip to content

Commit

Permalink
Move the "convertEs6TypedToEs6" to the very start of compilation.
Browse files Browse the repository at this point in the history
This change is to prevent passes which don't support TS syntax features (essentially all of them) from ever receiving code containing those features. Currently those passes ignore this condition, however a followup change will make that an error.

It is also necessary to update how the pass operates on rest parameters. Previously, it was generating unrecognized type annotations; they were being attached to the wrong node. This has been corrected.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=232744013
  • Loading branch information
nreid260 authored and tjgq committed Feb 7, 2019
1 parent 04e4749 commit 00f1ae7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ private void addTypeCheckerPasses(List<PassFactory> checks, CompilerOptions opti
protected List<PassFactory> getChecks() {
List<PassFactory> checks = new ArrayList<>();

if (options.needsTranspilationFrom(TYPESCRIPT)) {
checks.add(convertEs6TypedToEs6);
}

checks.add(gatherGettersAndSetters);

if (options.shouldGenerateTypedExterns()) {
Expand Down Expand Up @@ -268,10 +272,6 @@ protected List<PassFactory> getChecks() {
// Verify JsDoc annotations and check ES6 modules
checks.add(checkJsDocAndEs6Modules);

if (options.needsTranspilationFrom(TYPESCRIPT)) {
checks.add(convertEs6TypedToEs6);
}

checks.add(checkTypeImportCodeReferences);

checks.add(gatherModuleMetadataPass);
Expand Down
4 changes: 3 additions & 1 deletion src/com/google/javascript/jscomp/Es6TypedToEs6Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ public void visit(NodeTraversal t, Node n, Node parent) {
visitEnum(t, n, parent);
break;
case NAME:
case REST:
maybeVisitColonType(t, n, n);
break;
case REST:
maybeVisitColonType(t, n, n.getOnlyChild());
break;
case FUNCTION:
visitFunction(t, n, parent);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,27 +237,28 @@ public void testOptionalProperty_withES6Modules() {

@Test
public void testRestParameter() {
test("function f(...p1: number[]) {}", "function f(/** ...number */ ...p1) {}");
test("function f(...p1: number[]) {}", "function f(.../** ...number */ p1) {}");
testSame("function f(...p1) {}");
}

@Test
public void testRestParameter_withES6Modules() {
test("export function f(...p1: number[]) {}", "export function f(/** ...number */ ...p1) {}");
test("export function f(...p1: number[]) {}", "export function f(.../** ...number */ p1) {}");
}

@Test
public void testReturnType() {
test("function f(...p1: number[]): void {}",
"/** @return{void} */ function f(/** ...number */ ...p1) {}");
test(
"function f(...p1: number[]): void {}",
"/** @return{void} */ function f(.../** ...number */ p1) {}");
testSame("function f(...p1) {}");
}

@Test
public void testReturnType_withES6Modules() {
test(
"export function f(...p1: number[]): void {}",
"export /** @return{void} */ function f(/** ...number */ ...p1) {}");
"export /** @return{void} */ function f(.../** ...number */ p1) {}");
}

@Test
Expand Down

0 comments on commit 00f1ae7

Please sign in to comment.