Increased flexibility for multiline comment parsing

This commit is contained in:
Josh Goldberg
2020-04-30 23:06:14 -04:00
parent 992441d9b8
commit 199d256ba2
6 changed files with 174 additions and 124 deletions
File diff suppressed because one or more lines are too long
+24 -16
View File
@@ -1,21 +1,23 @@
tests/cases/conformance/directives/a.ts(10,1): error TS2578: Unused '@ts-expect-error' directive.
tests/cases/conformance/directives/b.tsx(26,1): error TS2578: Unused '@ts-expect-error' directive.
tests/cases/conformance/directives/a.ts(12,1): error TS2578: Unused '@ts-expect-error' directive.
tests/cases/conformance/directives/b.tsx(32,1): error TS2578: Unused '@ts-expect-error' directive.
==== tests/cases/conformance/directives/a.ts (1 errors) ====
export const texts: string[] = [];
/**
@ts-ignore */
export let x: string = 100;
texts.push(100);
/**
@ts-expect-error */
export let y: string = 100;
texts.push(100);
/**
@ts-expect-error */
~~~~~~~~~~~~~~~~~~~~
!!! error TS2578: Unused '@ts-expect-error' directive.
export let ok = 100;
texts.push("100");
==== tests/cases/conformance/directives/b.tsx (1 errors) ====
import * as React from "react";
@@ -28,25 +30,31 @@ tests/cases/conformance/directives/b.tsx(26,1): error TS2578: Unused '@ts-expect
<div>
{/*
@ts-ignore */}
<MyComponent foo={100} />;
</div>
);
<MyComponent foo={100} />
{/*@ts-ignore*/}
<MyComponent foo={100} />
let y = (
<div>
{/*
@ts-expect-error */}
<MyComponent foo={100} />;
</div>
);
<MyComponent foo={100} />
{/*
// @ts-expect-error */}
<MyComponent foo={100} />
{/*
* @ts-expect-error */}
<MyComponent foo={100} />
{/*@ts-expect-error*/}
<MyComponent foo={100} />
let ok = (
<div>
{/*
@ts-expect-error */}
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2578: Unused '@ts-expect-error' directive.
<MyComponent foo={"hooray"} />;
<MyComponent foo={"hooray"} />
</div>
);
+32 -24
View File
@@ -1,17 +1,19 @@
//// [tests/cases/conformance/directives/multiline.tsx] ////
//// [a.ts]
export const texts: string[] = [];
/**
@ts-ignore */
export let x: string = 100;
texts.push(100);
/**
@ts-expect-error */
export let y: string = 100;
texts.push(100);
/**
@ts-expect-error */
export let ok = 100;
texts.push("100");
//// [b.tsx]
import * as React from "react";
@@ -24,23 +26,29 @@ let x = (
<div>
{/*
@ts-ignore */}
<MyComponent foo={100} />;
</div>
);
<MyComponent foo={100} />
{/*@ts-ignore*/}
<MyComponent foo={100} />
let y = (
<div>
{/*
@ts-expect-error */}
<MyComponent foo={100} />;
</div>
);
<MyComponent foo={100} />
{/*
// @ts-expect-error */}
<MyComponent foo={100} />
{/*
* @ts-expect-error */}
<MyComponent foo={100} />
{/*@ts-expect-error*/}
<MyComponent foo={100} />
let ok = (
<div>
{/*
@ts-expect-error */}
<MyComponent foo={"hooray"} />;
<MyComponent foo={"hooray"} />
</div>
);
@@ -48,16 +56,17 @@ let ok = (
//// [a.js]
"use strict";
exports.__esModule = true;
exports.ok = exports.y = exports.x = void 0;
exports.texts = void 0;
exports.texts = [];
/**
@ts-ignore */
exports.x = 100;
exports.texts.push(100);
/**
@ts-expect-error */
exports.y = 100;
exports.texts.push(100);
/**
@ts-expect-error */
exports.ok = 100;
exports.texts.push("100");
//// [b.js]
"use strict";
exports.__esModule = true;
@@ -69,10 +78,9 @@ function MyComponent(props) {
exports.MyComponent = MyComponent;
var x = (React.createElement("div", null,
React.createElement(MyComponent, { foo: 100 }),
";"));
var y = (React.createElement("div", null,
React.createElement(MyComponent, { foo: 100 }),
";"));
var ok = (React.createElement("div", null,
React.createElement(MyComponent, { foo: "hooray" }),
";"));
React.createElement(MyComponent, { foo: 100 }),
React.createElement(MyComponent, { foo: 100 }),
React.createElement(MyComponent, { foo: 100 }),
React.createElement(MyComponent, { foo: 100 }),
React.createElement(MyComponent, { foo: "hooray" })));
+38 -29
View File
@@ -1,18 +1,27 @@
=== tests/cases/conformance/directives/a.ts ===
export const texts: string[] = [];
>texts : Symbol(texts, Decl(a.ts, 0, 12))
/**
@ts-ignore */
export let x: string = 100;
>x : Symbol(x, Decl(a.ts, 2, 10))
texts.push(100);
>texts.push : Symbol(Array.push, Decl(lib.d.ts, --, --))
>texts : Symbol(texts, Decl(a.ts, 0, 12))
>push : Symbol(Array.push, Decl(lib.d.ts, --, --))
/**
@ts-expect-error */
export let y: string = 100;
>y : Symbol(y, Decl(a.ts, 6, 10))
texts.push(100);
>texts.push : Symbol(Array.push, Decl(lib.d.ts, --, --))
>texts : Symbol(texts, Decl(a.ts, 0, 12))
>push : Symbol(Array.push, Decl(lib.d.ts, --, --))
/**
@ts-expect-error */
export let ok = 100;
>ok : Symbol(ok, Decl(a.ts, 10, 10))
texts.push("100");
>texts.push : Symbol(Array.push, Decl(lib.d.ts, --, --))
>texts : Symbol(texts, Decl(a.ts, 0, 12))
>push : Symbol(Array.push, Decl(lib.d.ts, --, --))
=== tests/cases/conformance/directives/b.tsx ===
import * as React from "react";
@@ -35,43 +44,43 @@ let x = (
{/*
@ts-ignore */}
<MyComponent foo={100} />;
<MyComponent foo={100} />
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
>foo : Symbol(foo, Decl(b.tsx, 10, 16))
</div>
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45))
);
let y = (
>y : Symbol(y, Decl(b.tsx, 14, 3))
<div>
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45))
{/*@ts-ignore*/}
<MyComponent foo={100} />
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
>foo : Symbol(foo, Decl(b.tsx, 13, 16))
{/*
@ts-expect-error */}
<MyComponent foo={100} />;
<MyComponent foo={100} />
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
>foo : Symbol(foo, Decl(b.tsx, 18, 16))
>foo : Symbol(foo, Decl(b.tsx, 17, 16))
</div>
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45))
{/*
// @ts-expect-error */}
<MyComponent foo={100} />
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
>foo : Symbol(foo, Decl(b.tsx, 21, 16))
);
{/*
* @ts-expect-error */}
<MyComponent foo={100} />
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
>foo : Symbol(foo, Decl(b.tsx, 25, 16))
let ok = (
>ok : Symbol(ok, Decl(b.tsx, 22, 3))
<div>
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45))
{/*@ts-expect-error*/}
<MyComponent foo={100} />
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
>foo : Symbol(foo, Decl(b.tsx, 28, 16))
{/*
@ts-expect-error */}
<MyComponent foo={"hooray"} />;
<MyComponent foo={"hooray"} />
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
>foo : Symbol(foo, Decl(b.tsx, 26, 16))
>foo : Symbol(foo, Decl(b.tsx, 32, 16))
</div>
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45))
+53 -36
View File
@@ -1,21 +1,34 @@
=== tests/cases/conformance/directives/a.ts ===
export const texts: string[] = [];
>texts : string[]
>[] : undefined[]
/**
@ts-ignore */
export let x: string = 100;
>x : string
texts.push(100);
>texts.push(100) : number
>texts.push : (...items: string[]) => number
>texts : string[]
>push : (...items: string[]) => number
>100 : 100
/**
@ts-expect-error */
export let y: string = 100;
>y : string
texts.push(100);
>texts.push(100) : number
>texts.push : (...items: string[]) => number
>texts : string[]
>push : (...items: string[]) => number
>100 : 100
/**
@ts-expect-error */
export let ok = 100;
>ok : number
>100 : 100
texts.push("100");
>texts.push("100") : number
>texts.push : (...items: string[]) => number
>texts : string[]
>push : (...items: string[]) => number
>"100" : "100"
=== tests/cases/conformance/directives/b.tsx ===
import * as React from "react";
@@ -33,57 +46,61 @@ export function MyComponent(props: { foo: string }) {
let x = (
>x : JSX.Element
>( <div> {/* @ts-ignore */} <MyComponent foo={100} />; </div>) : JSX.Element
>( <div> {/* @ts-ignore */} <MyComponent foo={100} /> {/*@ts-ignore*/} <MyComponent foo={100} /> {/* @ts-expect-error */} <MyComponent foo={100} /> {/* // @ts-expect-error */} <MyComponent foo={100} /> {/* * @ts-expect-error */} <MyComponent foo={100} /> {/*@ts-expect-error*/} <MyComponent foo={100} /> {/* @ts-expect-error */} <MyComponent foo={"hooray"} /> </div>) : JSX.Element
<div>
><div> {/* @ts-ignore */} <MyComponent foo={100} />; </div> : JSX.Element
><div> {/* @ts-ignore */} <MyComponent foo={100} /> {/*@ts-ignore*/} <MyComponent foo={100} /> {/* @ts-expect-error */} <MyComponent foo={100} /> {/* // @ts-expect-error */} <MyComponent foo={100} /> {/* * @ts-expect-error */} <MyComponent foo={100} /> {/*@ts-expect-error*/} <MyComponent foo={100} /> {/* @ts-expect-error */} <MyComponent foo={"hooray"} /> </div> : JSX.Element
>div : any
{/*
@ts-ignore */}
<MyComponent foo={100} />;
<MyComponent foo={100} />
><MyComponent foo={100} /> : JSX.Element
>MyComponent : (props: { foo: string; }) => JSX.Element
>foo : number
>100 : 100
</div>
>div : any
);
let y = (
>y : JSX.Element
>( <div> {/* @ts-expect-error */} <MyComponent foo={100} />; </div>) : JSX.Element
<div>
><div> {/* @ts-expect-error */} <MyComponent foo={100} />; </div> : JSX.Element
>div : any
{/*
@ts-expect-error */}
<MyComponent foo={100} />;
{/*@ts-ignore*/}
<MyComponent foo={100} />
><MyComponent foo={100} /> : JSX.Element
>MyComponent : (props: { foo: string; }) => JSX.Element
>foo : number
>100 : 100
</div>
>div : any
{/*
@ts-expect-error */}
<MyComponent foo={100} />
><MyComponent foo={100} /> : JSX.Element
>MyComponent : (props: { foo: string; }) => JSX.Element
>foo : number
>100 : 100
);
{/*
// @ts-expect-error */}
<MyComponent foo={100} />
><MyComponent foo={100} /> : JSX.Element
>MyComponent : (props: { foo: string; }) => JSX.Element
>foo : number
>100 : 100
let ok = (
>ok : JSX.Element
>( <div> {/* @ts-expect-error */} <MyComponent foo={"hooray"} />; </div>) : JSX.Element
{/*
* @ts-expect-error */}
<MyComponent foo={100} />
><MyComponent foo={100} /> : JSX.Element
>MyComponent : (props: { foo: string; }) => JSX.Element
>foo : number
>100 : 100
<div>
><div> {/* @ts-expect-error */} <MyComponent foo={"hooray"} />; </div> : JSX.Element
>div : any
{/*@ts-expect-error*/}
<MyComponent foo={100} />
><MyComponent foo={100} /> : JSX.Element
>MyComponent : (props: { foo: string; }) => JSX.Element
>foo : number
>100 : 100
{/*
@ts-expect-error */}
<MyComponent foo={"hooray"} />;
<MyComponent foo={"hooray"} />
><MyComponent foo={"hooray"} /> : JSX.Element
>MyComponent : (props: { foo: string; }) => JSX.Element
>foo : string
@@ -1,15 +1,17 @@
// @filename: a.ts
export const texts: string[] = [];
/**
@ts-ignore */
export let x: string = 100;
texts.push(100);
/**
@ts-expect-error */
export let y: string = 100;
texts.push(100);
/**
@ts-expect-error */
export let ok = 100;
texts.push("100");
// @filename: b.tsx
// @jsx: react
@@ -24,22 +26,28 @@ let x = (
<div>
{/*
@ts-ignore */}
<MyComponent foo={100} />;
</div>
);
<MyComponent foo={100} />
{/*@ts-ignore*/}
<MyComponent foo={100} />
let y = (
<div>
{/*
@ts-expect-error */}
<MyComponent foo={100} />;
</div>
);
<MyComponent foo={100} />
{/*
// @ts-expect-error */}
<MyComponent foo={100} />
{/*
* @ts-expect-error */}
<MyComponent foo={100} />
{/*@ts-expect-error*/}
<MyComponent foo={100} />
let ok = (
<div>
{/*
@ts-expect-error */}
<MyComponent foo={"hooray"} />;
<MyComponent foo={"hooray"} />
</div>
);