Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingwl committed Jan 3, 2019
1 parent b2f76e9 commit 9143748
Show file tree
Hide file tree
Showing 12 changed files with 506 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4317,7 +4317,7 @@ namespace ts {
}

const tagName = parseJsxElementName();
const typeArguments = tryParseTypeArguments();
const typeArguments = isSourceFileNotJS(sourceFile) ? tryParseTypeArguments() : undefined;
const attributes = parseJsxAttributes();

let node: JsxOpeningLikeElement;
Expand Down Expand Up @@ -4528,7 +4528,7 @@ namespace ts {
// keep checking for postfix expressions. Otherwise, it's just a '<' that's
// part of an arithmetic expression. Break out so we consume it higher in the
// stack.
const typeArguments = tryParse(parseTypeArgumentsInExpression);
const typeArguments = isSourceFileNotJS(sourceFile) && tryParse(parseTypeArgumentsInExpression);
if (!typeArguments) {
return expression;
}
Expand Down Expand Up @@ -4823,7 +4823,7 @@ namespace ts {
let typeArguments;
while (true) {
expression = parseMemberExpressionRest(expression);
typeArguments = tryParse(parseTypeArgumentsInExpression);
typeArguments = isSourceFileNotJS(sourceFile) ? tryParse(parseTypeArgumentsInExpression) : undefined;
if (isTemplateStartOfTaggedTemplate()) {
Debug.assert(!!typeArguments,
"Expected a type argument list; all plain tagged template starts should be consumed in 'parseMemberExpressionRest'");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
tests/cases/compiler/a.js(1,5): error TS8011: 'type arguments' can only be used in a .ts file.
tests/cases/compiler/a.js(1,13): error TS1109: Expression expected.


!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file.
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
==== tests/cases/compiler/a.js (1 errors) ====
Foo<number>();
~~~~~~
!!! error TS8011: 'type arguments' can only be used in a .ts file.
~
!!! error TS1109: Expression expected.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
=== tests/cases/compiler/a.js ===
Foo<number>();
>Foo<number>() : any
>Foo<number>() : boolean
>Foo<number : boolean
>Foo : any
>number : any
>() : any
> : any

Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
tests/cases/conformance/jsx/file.jsx(4,17): error TS8011: 'type arguments' can only be used in a .ts file.
tests/cases/conformance/jsx/file.jsx(4,9): error TS2695: Left side of comma operator is unused and has no side effects.
tests/cases/conformance/jsx/file.jsx(4,16): error TS1003: Identifier expected.
tests/cases/conformance/jsx/file.jsx(4,17): error TS2693: 'Prop' only refers to a type, but is being used as a value here.
tests/cases/conformance/jsx/file.jsx(4,17): error TS17008: JSX element 'Prop' has no corresponding closing tag.
tests/cases/conformance/jsx/file.jsx(5,1): error TS1005: '</' expected.


==== tests/cases/conformance/jsx/component.d.ts (0 errors) ====
Expand All @@ -12,11 +16,19 @@ tests/cases/conformance/jsx/file.jsx(4,17): error TS8011: 'type arguments' can o
b: string
}

==== tests/cases/conformance/jsx/file.jsx (1 errors) ====
==== tests/cases/conformance/jsx/file.jsx (5 errors) ====
import { MyComp, Prop } from "./component";
import * as React from "react";

let x = <MyComp<Prop> a={10} b="hi" />; // error, no type arguments in js
~~~~~~~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
~
!!! error TS1003: Identifier expected.
~~~~
!!! error TS8011: 'type arguments' can only be used in a .ts file.

!!! error TS2693: 'Prop' only refers to a type, but is being used as a value here.
~~~~
!!! error TS17008: JSX element 'Prop' has no corresponding closing tag.


!!! error TS1005: '</' expected.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ let x = <MyComp<Prop> a={10} b="hi" />; // error, no type arguments in js
exports.__esModule = true;
var component_1 = require("./component");
var React = require("react");
var x = <component_1.MyComp a={10} b="hi"/>; // error, no type arguments in js
var x = <component_1.MyComp />, <Prop> a={10} b="hi" />; // error, no type arguments in js
</>;
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,4 @@ import * as React from "react";
let x = <MyComp<Prop> a={10} b="hi" />; // error, no type arguments in js
>x : Symbol(x, Decl(file.jsx, 3, 3))
>MyComp : Symbol(MyComp, Decl(file.jsx, 0, 8))
>Prop : Symbol(Prop, Decl(file.jsx, 0, 16))
>a : Symbol(a, Decl(file.jsx, 3, 21))
>b : Symbol(b, Decl(file.jsx, 3, 28))

Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ import * as React from "react";

let x = <MyComp<Prop> a={10} b="hi" />; // error, no type arguments in js
>x : JSX.Element
><MyComp<Prop> a={10} b="hi" /> : JSX.Element
><MyComp<Prop> a={10} b="hi" />; // error, no type arguments in js : JSX.Element
><MyComp : JSX.Element
>MyComp : typeof MyComp
>a : number
><Prop> a={10} b="hi" />; // error, no type arguments in js : JSX.Element
>Prop : any
>10 : 10
>b : string

> : any

91 changes: 91 additions & 0 deletions tests/baselines/reference/typeArgumentsInJs.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
tests/cases/compiler/a.js(1,4): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.
tests/cases/compiler/a.js(4,1): error TS2365: Operator '<' cannot be applied to types '() => void' and 'number'.
tests/cases/compiler/a.js(4,7): error TS1109: Expression expected.
tests/cases/compiler/a.js(5,11): error TS1109: Expression expected.
tests/cases/compiler/a.js(8,1): error TS2365: Operator '<' cannot be applied to types '(a: any) => void' and 'number'.
tests/cases/compiler/a.js(8,1): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string'.
tests/cases/compiler/a.js(11,9): error TS1146: Declaration expected.
tests/cases/compiler/a.js(11,9): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.
tests/cases/compiler/b.jsx(1,4): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.
tests/cases/compiler/b.jsx(4,12): error TS2695: Left side of comma operator is unused and has no side effects.
tests/cases/compiler/b.jsx(4,18): error TS1003: Identifier expected.
tests/cases/compiler/b.jsx(4,19): error TS1003: Identifier expected.
tests/cases/compiler/b.jsx(4,22): error TS1109: Expression expected.
tests/cases/compiler/b.jsx(4,30): error TS1109: Expression expected.
tests/cases/compiler/c.ts(1,4): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures.
tests/cases/compiler/d.tsx(1,4): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures.


==== tests/cases/compiler/a.js (8 errors) ====
if((0)<0>(0)){ }
~~~~~~~~~
!!! error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.

function f1() {}
f1<1>();
~~~~
!!! error TS2365: Operator '<' cannot be applied to types '() => void' and 'number'.
~
!!! error TS1109: Expression expected.
new f1<1>();
~
!!! error TS1109: Expression expected.

function t1(a) {}
t1<1>``;
~~~~
!!! error TS2365: Operator '<' cannot be applied to types '(a: any) => void' and 'number'.
~~~~~~~
!!! error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string'.

function sealed1(a) { return function seal(ctor) {} }
@sealed1<1>(1)

!!! error TS1146: Declaration expected.
~~~~~~
!!! error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.
class Greeter1 {}

==== tests/cases/compiler/b.jsx (6 errors) ====
if((0)<0>(0)){ }
~~~~~~~~~
!!! error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.

function Test1() {}
const a1 = <Test1<1>></Test1>;
~~~~~~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
~
!!! error TS1003: Identifier expected.
~
!!! error TS1003: Identifier expected.
~~
!!! error TS1109: Expression expected.
~
!!! error TS1109: Expression expected.

==== tests/cases/compiler/c.ts (1 errors) ====
if((0)<0>(0)){ }
~~~~~~~~~
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures.

function f2<T>() {}
f2<1>();
new f2<1>();

function t2<T>(a) {}
t2<1>``;

function sealed2<T>(a: T) { return function seal(ctor) {} }
@sealed2<1>(1)
class Greeter2 {}

==== tests/cases/compiler/d.tsx (1 errors) ====
if((0)<0>(0)){ }
~~~~~~~~~
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures.

function Test2<T>() {}
const a2 = <Test2<1>></Test2>


94 changes: 94 additions & 0 deletions tests/baselines/reference/typeArgumentsInJs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//// [tests/cases/compiler/typeArgumentsInJs.ts] ////

//// [a.js]
if((0)<0>(0)){ }

function f1() {}
f1<1>();
new f1<1>();

function t1(a) {}
t1<1>``;

function sealed1(a) { return function seal(ctor) {} }
@sealed1<1>(1)
class Greeter1 {}

//// [b.jsx]
if((0)<0>(0)){ }

function Test1() {}
const a1 = <Test1<1>></Test1>;

//// [c.ts]
if((0)<0>(0)){ }

function f2<T>() {}
f2<1>();
new f2<1>();

function t2<T>(a) {}
t2<1>``;

function sealed2<T>(a: T) { return function seal(ctor) {} }
@sealed2<1>(1)
class Greeter2 {}

//// [d.tsx]
if((0)<0>(0)){ }

function Test2<T>() {}
const a2 = <Test2<1>></Test2>



//// [a.js]
if ((0) < 0 > (0)) { }
function f1() { }
f1 < 1 > ();
new f1 < 1 > ();
function t1(a) { }
t1 < 1 > "";
function sealed1(a) { return function seal(ctor) { }; }
< 1 > (1);
var Greeter1 = /** @class */ (function () {
function Greeter1() {
}
return Greeter1;
}());
//// [b.jsx]
if ((0) < 0 > (0)) { }
function Test1() { }
var a1 = <Test1 />, < />;
1 >> ;
Test1 > ;
//// [c.js]
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
if ((0)(0)) { }
function f2() { }
f2();
new f2();
function t2(a) { }
t2(__makeTemplateObject([""], [""]));
function sealed2(a) { return function seal(ctor) { }; }
var Greeter2 = /** @class */ (function () {
function Greeter2() {
}
Greeter2 = __decorate([
sealed2(1)
], Greeter2);
return Greeter2;
}());
//// [d.jsx]
if ((0)(0)) { }
function Test2() { }
var a2 = <Test2></Test2>;
90 changes: 90 additions & 0 deletions tests/baselines/reference/typeArgumentsInJs.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
=== tests/cases/compiler/a.js ===
if((0)<0>(0)){ }

function f1() {}
>f1 : Symbol(f1, Decl(a.js, 0, 16))

f1<1>();
>f1 : Symbol(f1, Decl(a.js, 0, 16))

new f1<1>();
>f1 : Symbol(f1, Decl(a.js, 0, 16))

function t1(a) {}
>t1 : Symbol(t1, Decl(a.js, 4, 12))
>a : Symbol(a, Decl(a.js, 6, 12))

t1<1>``;
>t1 : Symbol(t1, Decl(a.js, 4, 12))

function sealed1(a) { return function seal(ctor) {} }
>sealed1 : Symbol(sealed1, Decl(a.js, 7, 8))
>a : Symbol(a, Decl(a.js, 9, 17))
>seal : Symbol(seal, Decl(a.js, 9, 28))
>ctor : Symbol(ctor, Decl(a.js, 9, 43))

@sealed1<1>(1)
>sealed1 : Symbol(sealed1, Decl(a.js, 7, 8))

class Greeter1 {}
>Greeter1 : Symbol(Greeter1, Decl(a.js, 10, 14))

=== tests/cases/compiler/b.jsx ===
if((0)<0>(0)){ }

function Test1() {}
>Test1 : Symbol(Test1, Decl(b.jsx, 0, 16))

const a1 = <Test1<1>></Test1>;
>a1 : Symbol(a1, Decl(b.jsx, 3, 5))
>Test1 : Symbol(Test1, Decl(b.jsx, 0, 16))
>Test1 : Symbol(Test1, Decl(b.jsx, 0, 16))

=== tests/cases/compiler/c.ts ===
if((0)<0>(0)){ }

function f2<T>() {}
>f2 : Symbol(f2, Decl(c.ts, 0, 16))
>T : Symbol(T, Decl(c.ts, 2, 12))

f2<1>();
>f2 : Symbol(f2, Decl(c.ts, 0, 16))

new f2<1>();
>f2 : Symbol(f2, Decl(c.ts, 0, 16))

function t2<T>(a) {}
>t2 : Symbol(t2, Decl(c.ts, 4, 12))
>T : Symbol(T, Decl(c.ts, 6, 12))
>a : Symbol(a, Decl(c.ts, 6, 15))

t2<1>``;
>t2 : Symbol(t2, Decl(c.ts, 4, 12))

function sealed2<T>(a: T) { return function seal(ctor) {} }
>sealed2 : Symbol(sealed2, Decl(c.ts, 7, 8))
>T : Symbol(T, Decl(c.ts, 9, 17))
>a : Symbol(a, Decl(c.ts, 9, 20))
>T : Symbol(T, Decl(c.ts, 9, 17))
>seal : Symbol(seal, Decl(c.ts, 9, 34))
>ctor : Symbol(ctor, Decl(c.ts, 9, 49))

@sealed2<1>(1)
>sealed2 : Symbol(sealed2, Decl(c.ts, 7, 8))

class Greeter2 {}
>Greeter2 : Symbol(Greeter2, Decl(c.ts, 9, 59))

=== tests/cases/compiler/d.tsx ===
if((0)<0>(0)){ }

function Test2<T>() {}
>Test2 : Symbol(Test2, Decl(d.tsx, 0, 16))
>T : Symbol(T, Decl(d.tsx, 2, 15))

const a2 = <Test2<1>></Test2>
>a2 : Symbol(a2, Decl(d.tsx, 3, 5))
>Test2 : Symbol(Test2, Decl(d.tsx, 0, 16))
>Test2 : Symbol(Test2, Decl(d.tsx, 0, 16))


Loading

0 comments on commit 9143748

Please sign in to comment.