file_path stringlengths 3 280 | file_language stringclasses 66 values | content stringlengths 1 1.04M | repo_name stringlengths 5 92 | repo_stars int64 0 154k | repo_description stringlengths 0 402 | repo_primary_language stringclasses 108 values | developer_username stringlengths 1 25 | developer_name stringlengths 0 30 | developer_company stringlengths 0 82 |
|---|---|---|---|---|---|---|---|---|---|
crates/swc_ecma_parser/tests/tsc/jsdocImportTypeReferenceToESModule.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: ex.d.ts
export var config: {}
// @Filename: test.js
/** @param {import('./ex')} a */
function demo(a) {
a.config
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocImportTypeReferenceToStringLiteral.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: b.js
export const FOO = "foo";
// @Filename: a.js
/** @type {import('./b').FOO} */
let x;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocIndexSignature.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: indices.js
/** @type {Object.<string, number>} */
var o1;
/** @type {Object.<number, boolean>} */
var o2;
/** @type {Object.<boolean, string>} */
var o3;
/** @param {Object.<string, boolean>} o */
function f(o) {
o.foo = 1; // error
o.bar = false; // ok
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocInvalidTokens.ts | TypeScript | // @Filename: jsdocInvalidTokens.js
// @strict: true
// @allowJs: true
// @checkJs: true
// @noEmit: true
/**
*
* unicode-escape = "\u{abcdefghi}" -- should not have error for invalid unicode escape
* unicode-escape2 = "qq\u{abcdefghi}" -- no error here either
* quoted-pair = "\" -- should not have error for invalid quote sequence
* or for the tag below:
* @private
*/
var hi = 1
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocLinkTag1.ts | TypeScript | // @noUnusedLocals: true
// @filename: /a.ts
export interface A {}
// @filename: /b.ts
import type { A } from "./a";
/** {@link A} */
export interface B {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocLinkTag2.ts | TypeScript | // @noUnusedLocals: true
// @checkJs: true
// @allowJs: true
// @target: esnext
// @noEmit: true
// @filename: /a.js
export class A {}
// @filename: /b.js
import { A } from "./a";
/** {@link A} */
export class B {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocLinkTag3.ts | TypeScript | // @noUnusedLocals: true
// @filename: /a.ts
export interface A {}
// @filename: /b.ts
import type { A } from "./a";
/**
* @param {number} a - see {@link A}
*/
export function foo(a: string) {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocLinkTag4.ts | TypeScript | // @noUnusedLocals: true
// @filename: /a.ts
export interface A {}
// @filename: /b.ts
import * as a from "./a";
/**
* @param {number} a - see {@link a.A}
*/
export function foo(a: string) {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocLinkTag5.ts | TypeScript | // @noUnusedLocals: true
// @filename: /a.ts
/** {@link UNRESOLVED_LINK} */
export interface A {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocLinkTag6.ts | TypeScript | // @filename: /a.ts
class A {
foo() {}
}
class B extends A {
/**
* @override {@link A.foo}
*/
foo() {}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocLinkTag7.ts | TypeScript | // @checkJs: true
// @allowJs: true
// @target: esnext
// @noEmit: true
// @filename: /a.js
class Foo {
/**
* {@linkcode this.a}
* {@linkcode this.#c}
*
* {@link this.a}
* {@link this.#c}
*
* {@linkplain this.a}
* {@linkplain this.#c}
*/
a() { }
b() { }
#c() { }
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocLinkTag8.ts | TypeScript | // @checkJs: true
// @allowJs: true
// @target: esnext
// @noEmit: true
// @filename: /a.js
/** {@link Map.delete} */
const remove = (map, key) => {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocLiteral.ts | TypeScript | // @allowJs: true
// @filename: in.js
// @outFile: out.js
/**
* @param {'literal'} p1
* @param {"literal"} p2
* @param {'literal' | 'other'} p3
* @param {'literal' | number} p4
* @param {12 | true | 'str'} p5
*/
function f(p1, p2, p3, p4, p5) {
return p1 + p2 + p3 + p4 + p5 + '.';
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocNeverUndefinedNull.ts | TypeScript | // @allowJs: true
// @filename: in.js
// @outFile: out.js
/**
* @param {never} p1
* @param {undefined} p2
* @param {null} p3
* @returns {void} nothing
*/
function f(p1, p2, p3) {
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocOuterTypeParameters1.ts | TypeScript | // @checkjs: true
// @filename: jsdocOuterTypeParameters1.js
/** @return {T} */
const dedupingMixin = function(mixin) {};
/** @template {T} */
const PropertyAccessors = dedupingMixin(() => {
class Bar {
static bar() { this.prototype.foo(); }
}
});
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocOuterTypeParameters2.ts | TypeScript | // @checkjs: true
// @filename: jsdocOuterTypeParameters1.js
/** @return {T} */
const dedupingMixin = function(mixin) {};
/** @template T */
const PropertyAccessors = dedupingMixin(() => {
class Bar {
static bar() { this.prototype.foo(); }
}
});
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocOuterTypeParameters3.ts | TypeScript | // @checkjs: true
// @filename: jsdocOuterTypeParameters3.js
/** @template {T} */
class Baz {
m() {
class Bar {
static bar() { this.prototype.foo(); }
}
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocOverrideTag1.ts | TypeScript | // @allowJS: true
// @checkJS: true
// @noEmit: true
// @noImplicitOverride: true
// @Filename: 0.js
class A {
/**
* @method
* @param {string | number} a
* @returns {boolean}
*/
foo (a) {
return typeof a === 'string'
}
bar () {
}
}
class B extends A {
/**
* @override
* @method
* @param {string | number} a
* @returns {boolean}
*/
foo (a) {
return super.foo(a)
}
bar () {
}
/** @override */
baz () {
}
}
class C {
/** @override */
foo () {
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocParamTag2.ts | TypeScript | // @allowJS: true
// @checkJS: true
// @noEmit: true
// @Filename: 0.js
// Object literal syntax
/**
* @param {{a: string, b: string}} obj
* @param {string} x
*/
function good1({a, b}, x) {}
/**
* @param {{a: string, b: string}} obj
* @param {{c: number, d: number}} OBJECTION
*/
function good2({a, b}, {c, d}) {}
/**
* @param {number} x
* @param {{a: string, b: string}} obj
* @param {string} y
*/
function good3(x, {a, b}, y) {}
/**
* @param {{a: string, b: string}} obj
*/
function good4({a, b}) {}
// nested object syntax
/**
* @param {Object} obj
* @param {string} obj.a - this is like the saddest way to specify a type
* @param {string} obj.b - but it sure does allow a lot of documentation
* @param {string} x
*/
function good5({a, b}, x) {}
/**
* @param {Object} obj
* @param {string} obj.a
* @param {string} obj.b - but it sure does allow a lot of documentation
* @param {Object} OBJECTION - documentation here too
* @param {string} OBJECTION.c
* @param {string} OBJECTION.d - meh
*/
function good6({a, b}, {c, d}) {}
/**
* @param {number} x
* @param {Object} obj
* @param {string} obj.a
* @param {string} obj.b
* @param {string} y
*/
function good7(x, {a, b}, y) {}
/**
* @param {Object} obj
* @param {string} obj.a
* @param {string} obj.b
*/
function good8({a, b}) {}
/**
* @param {{ a: string }} argument
*/
function good9({ a }) {
console.log(arguments, a);
}
/**
* @param {object} obj - this type gets ignored
* @param {string} obj.a
* @param {string} obj.b - and x's type gets used for both parameters
* @param {string} x
*/
function bad1(x, {a, b}) {}
/**
* @param {string} y - here, y's type gets ignored but obj's is fine
* @param {{a: string, b: string}} obj
*/
function bad2(x, {a, b}) {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocParamTagTypeLiteral.ts | TypeScript | // @allowJS: true
// @checkJs: true
// @noEmit: true
// @strict: true
// @suppressOutputPathCheck: true
// @Filename: 0.js
/**
* @param {Object} notSpecial
* @param {string} unrelated - not actually related because it's not notSpecial.unrelated
*/
function normal(notSpecial) {
notSpecial; // should just be 'Object'
}
normal(12);
/**
* @param {Object} opts1 doc1
* @param {string} opts1.x doc2
* @param {string=} opts1.y doc3
* @param {string} [opts1.z] doc4
* @param {string} [opts1.w="hi"] doc5
*/
function foo1(opts1) {
opts1.x;
}
foo1({x: 'abc'});
/**
* @param {Object[]} opts2
* @param {string} opts2[].anotherX
* @param {string=} opts2[].anotherY
*/
function foo2(/** @param opts2 bad idea theatre! */opts2) {
opts2[0].anotherX;
}
foo2([{anotherX: "world"}]);
/**
* @param {object} opts3
* @param {string} opts3.x
*/
function foo3(opts3) {
opts3.x;
}
foo3({x: 'abc'});
/**
* @param {object[]} opts4
* @param {string} opts4[].x
* @param {string=} opts4[].y
* @param {string} [opts4[].z]
* @param {string} [opts4[].w="hi"]
*/
function foo4(opts4) {
opts4[0].x;
}
foo4([{ x: 'hi' }]);
/**
* @param {object[]} opts5 - Let's test out some multiple nesting levels
* @param {string} opts5[].help - (This one is just normal)
* @param {object} opts5[].what - Look at us go! Here's the first nest!
* @param {string} opts5[].what.a - (Another normal one)
* @param {Object[]} opts5[].what.bad - Now we're nesting inside a nested type
* @param {string} opts5[].what.bad[].idea - I don't think you can get back out of this level...
* @param {boolean} opts5[].what.bad[].oh - Oh ... that's how you do it.
* @param {number} opts5[].unnest - Here we are almost all the way back at the beginning.
*/
function foo5(opts5) {
opts5[0].what.bad[0].idea;
opts5[0].unnest;
}
foo5([{ help: "help", what: { a: 'a', bad: [{ idea: 'idea', oh: false }] }, unnest: 1 }]);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocParseBackquotedParamName.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
// @Filename: a.js
/**
* @param {string=} `args`
* @param `bwarg` {?number?}
*/
function f(args, bwarg) {
}
// @Filename: ts.ts
/**
* @param `arg` - this is fine
*/
function g(arg: string) {
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocParseDotDotDotInJSDocFunction.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
// @Filename: a.js
// from bcryptjs
/** @param {function(...[*])} callback */
function g(callback) {
callback([1], [2], [3])
}
/**
* @type {!function(...number):string}
* @inner
*/
var stringFromCharCode = String.fromCharCode;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocParseHigherOrderFunction.ts | TypeScript | // @noemit: true
// @allowjs: true
// @checkjs: true
// @strict: true
// @Filename: paren.js
/** @type {function((string), function((string)): string): string} */
var x = (s, id) => id(s)
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocParseMatchingBackticks.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
// @Filename: jsdocParseMatchingBackticks.js
/**
* `@param` initial at-param is OK in title comment
* @param {string} x hi there `@param`
* @param {string} y hi there `@ * param
* this is the margin
* so we'll drop everything before it
`@param` @param {string} z hello???
* `@param` @param {string} alpha hello???
* `@ * param` @param {string} beta hello???
* @param {string} gamma
*/
export function f(x, y, z, alpha, beta, gamma) {
return x + y + z + alpha + beta + gamma
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocParseParenthesizedJSDocParameter.ts | TypeScript | // @noemit: true
// @allowjs: true
// @checkjs: true
// @strict: true
// @Filename: paren.js
/** @type {function((string)): string} */
var x = s => s.toString()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocParseStarEquals.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
// @Filename: a.js
/** @param {...*=} args
@return {*=} */
function f(...args) {
return null
}
/** @type *= */
var x;
/** @param {function():*=} f */
function cbf(f) {
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocPostfixEqualsAddsOptionality.ts | TypeScript | // @Filename: a.js
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
/** @param {number=} a */
function f(a) {
a = 1
a = null // should not be allowed
a = undefined
}
f()
f(null) // should not be allowed
f(undefined)
f(1)
/** @param {???!?number?=} a */
function g(a) {
a = 1
a = null
a = undefined
}
g()
g(null)
g(undefined)
g(1)
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocPrefixPostfixParsing.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strictNullChecks: true
// @noImplicitAny: true
// @Filename: prefixPostfix.js
/**
* @param {number![]} x - number[]
* @param {!number[]} y - number[]
* @param {(number[])!} z - number[]
* @param {number?[]} a - parse error without parentheses
* @param {?number[]} b - number[] | null
* @param {(number[])?} c - number[] | null
* @param {...?number} e - (number | null)[]
* @param {...number?} f - number[] | null
* @param {...number!?} g - number[] | null
* @param {...number?!} h - parse error without parentheses (also nonsensical)
* @param {...number[]} i - number[][]
* @param {...number![]?} j - number[][] | null
* @param {...number?[]!} k - parse error without parentheses
* @param {number extends number ? true : false} l - conditional types work
* @param {[number, number?]} m - [number, (number | undefined)?]
*/
function f(x, y, z, a, b, c, e, f, g, h, i, j, k, l, m) {
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocPrivateName1.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @lib: dom,esnext
// @Filename: jsdocPrivateName1.js
// @target: es2015
class A {
/** @type {boolean} some number value */
#foo = 3 // Error because not assignable to boolean
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocPrivateName2.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @lib: dom,esnext
// @Filename: jsdocPrivateName1.js
// Expecting parse error for private field
/**
* @typedef A
* @type {object}
* @property {string} #id
*/
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocPrototypePropertyAccessWithType.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: /a.js
function C() { this.x = false; };
/** @type {number} */
C.prototype.x;
new C().x;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocReadonly.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @target: esnext
// @noEmit: true
// @Filename: jsdocReadonly.js
class LOL {
/**
* @readonly
* @private
* @type {number}
* Order rules do not apply to JSDoc
*/
x = 1
/** @readonly */
y = 2
/** @readonly Definitely not here */
static z = 3
/** @readonly This is OK too */
constructor() {
/** ok */
this.y = 2
/** @readonly ok */
this.ka = 2
}
}
var l = new LOL()
l.y = 12
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocReadonlyDeclarations.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @target: esnext
// @outFile: foo.js
// @declaration: true
// @Filename: jsdocReadonlyDeclarations.js
// @useDefineForClassFields: false
class C {
/** @readonly */
x = 6
/** @readonly */
constructor(n) {
this.x = n
/**
* @readonly
* @type {number}
*/
this.y = n
}
}
new C().x
function F() {
/** @readonly */
this.z = 1
}
// https://github.com/microsoft/TypeScript/issues/38401
class D {
constructor(/** @readonly */ x) {}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocReturnTag1.ts | TypeScript | // @allowJs: true
// @filename: returns.js
// @outFile: dummy.js
/**
* @returns {string} This comment is not currently exposed
*/
function f() {
return 5;
}
/**
* @returns {string=} This comment is not currently exposed
*/
function f1() {
return 5;
}
/**
* @returns {string|number} This comment is not currently exposed
*/
function f2() {
return 5 || "hello";
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocSignatureOnReturnedFunction.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @target: esnext
// @noImplicitAny: true
// @declaration: true
// @outDir: out
// @Filename: jsdocSignatureOnReturnedFunction.js
function f1() {
/**
* @param {number} a
* @param {number} b
* @returns {number}
*/
return (a, b) => {
return a + b;
}
}
function f2() {
/**
* @param {number} a
* @param {number} b
* @returns {number}
*/
return function (a, b){
return a + b;
}
}
function f3() {
/** @type {(a: number, b: number) => number} */
return (a, b) => {
return a + b;
}
}
function f4() {
/** @type {(a: number, b: number) => number} */
return function (a, b){
return a + b;
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTemplateClass.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: templateTagOnClasses.js
/**
* @template T
* @typedef {(t: T) => T} Id
*/
/** @template T */
class Foo {
/** @typedef {(t: T) => T} Id2 */
/** @param {T} x */
constructor (x) {
this.a = x
}
/**
*
* @param {T} x
* @param {Id<T>} y
* @param {Id2} alpha
* @return {T}
*/
foo(x, y, alpha) {
return alpha(y(x))
}
}
var f = new Foo(1)
var g = new Foo(false)
f.a = g.a
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTemplateConstructorFunction.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: templateTagOnConstructorFunctions.js
/**
* @template U
* @typedef {(u: U) => U} Id
*/
/**
* @param {T} t
* @template T
*/
function Zet(t) {
/** @type {T} */
this.u
this.t = t
}
/**
* @param {T} v
* @param {Id<T>} id
*/
Zet.prototype.add = function(v, id) {
this.u = v || this.t
return id(this.u)
}
var z = new Zet(1)
z.t = 2
z.u = false
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTemplateConstructorFunction2.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: templateTagWithNestedTypeLiteral.js
/**
* @param {T} t
* @template T
*/
function Zet(t) {
/** @type {T} */
this.u
this.t = t
}
/**
* @param {T} v
* @param {object} o
* @param {T} o.nested
*/
Zet.prototype.add = function(v, o) {
this.u = v || o.nested
return this.u
}
var z = new Zet(1)
z.t = 2
z.u = false
/** @type {number} */
let answer = z.add(3, { nested: 4 })
// lookup in typedef should not crash the compiler, even when the type is unknown
/**
* @typedef {Object} A
* @property {T} value
*/
/** @type {A} */
const options = { value: null };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTemplateTag.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @lib: dom,esnext
// @Filename: forgot.js
/**
* @param {T} a
* @template T
*/
function f(a) {
return () => a
}
let n = f(1)()
/**
* @param {T} a
* @template T
* @returns {function(): T}
*/
function g(a) {
return () => a
}
let s = g('hi')()
/**
* @param {Array.<Object>} keyframes - Can't look up types on Element since it's a global in another file. (But it shouldn't crash).
*/
Element.prototype.animate = function(keyframes) {};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTemplateTag2.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @lib: dom,esnext
// @Filename: github17339.js
var obj = {
/**
* @template T
* @param {T} a
* @returns {T}
*/
x: function (a) {
return a;
},
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTemplateTag3.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: a.js
/**
* @template {{ a: number, b: string }} T,U A Comment
* @template {{ c: boolean }} V uh ... are comments even supported??
* @template W
* @template X That last one had no comment
* @param {T} t
* @param {U} u
* @param {V} v
* @param {W} w
* @param {X} x
* @return {W | X}
*/
function f(t, u, v, w, x) {
if(t.a + t.b.length > u.a - u.b.length && v.c) {
return w;
}
return x;
}
f({ a: 12, b: 'hi', c: null }, undefined, { c: false, d: 12, b: undefined }, 101, 'nope');
f({ a: 12 }, undefined, undefined, 101, 'nope');
/**
* @template {NoLongerAllowed}
* @template T preceding line's syntax is no longer allowed
* @param {T} x
*/
function g(x) { }
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTemplateTag4.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
// @Filename: a.js
/**
* Should work for function declarations
* @constructor
* @template {string} K
* @template V
*/
function Multimap() {
/** @type {Object<string, V>} TODO: Remove the prototype from the fresh object */
this._map = {};
};
/**
* @param {K} key the key ok
* @returns {V} the value ok
*/
Multimap.prototype.get = function (key) {
return this._map[key + ''];
}
/**
* Should work for initialisers too
* @constructor
* @template {string} K
* @template V
*/
var Multimap2 = function() {
/** @type {Object<string, V>} TODO: Remove the prototype from the fresh object */
this._map = {};
};
/**
* @param {K} key the key ok
* @returns {V} the value ok
*/
Multimap2.prototype.get = function (key) {
return this._map[key + ''];
}
var Ns = {};
/**
* Should work for expando-namespaced initialisers too
* @constructor
* @template {string} K
* @template V
*/
Ns.Multimap3 = function() {
/** @type {Object<string, V>} TODO: Remove the prototype from the fresh object */
this._map = {};
};
/**
* @param {K} key the key ok
* @returns {V} the value ok
*/
Ns.Multimap3.prototype.get = function (key) {
return this._map[key + ''];
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTemplateTag5.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
// @Filename: a.js
/**
* Should work for function declarations
* @constructor
* @template {string} K
* @template V
*/
function Multimap() {
/** @type {Object<string, V>} TODO: Remove the prototype from the fresh object */
this._map = {};
};
Multimap.prototype = {
/**
* @param {K} key the key ok
* @returns {V} the value ok
*/
get(key) {
return this._map[key + ''];
}
}
/**
* Should work for initialisers too
* @constructor
* @template {string} K
* @template V
*/
var Multimap2 = function() {
/** @type {Object<string, V>} TODO: Remove the prototype from the fresh object */
this._map = {};
};
Multimap2.prototype = {
/**
* @param {K} key the key ok
* @returns {V} the value ok
*/
get: function(key) {
return this._map[key + ''];
}
}
var Ns = {};
/**
* Should work for expando-namespaced initialisers too
* @constructor
* @template {string} K
* @template V
*/
Ns.Multimap3 = function() {
/** @type {Object<string, V>} TODO: Remove the prototype from the fresh object */
this._map = {};
};
Ns.Multimap3.prototype = {
/**
* @param {K} key the key ok
* @returns {V} the value ok
*/
get(key) {
return this._map[key + ''];
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTemplateTag6.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
// @Filename: a.js
/**
* @template const T
* @param {T} x
* @returns {T}
*/
function f1(x) {
return x;
}
const t1 = f1("a");
const t2 = f1(["a", ["b", "c"]]);
const t3 = f1({ a: 1, b: "c", d: ["e", 2, true, { f: "g" }] });
/**
* @template const T, U
* @param {T} x
* @returns {T}
*/
function f2(x) {
return x;
};
const t4 = f2('a');
const t5 = f2(['a', ['b', 'c']]);
const t6 = f2({ a: 1, b: "c", d: ["e", 2, true, { f: "g" }] });
/**
* @template const T
* @param {T} x
* @returns {T[]}
*/
function f3(x) {
return [x];
}
const t7 = f3("hello");
const t8 = f3("hello");
/**
* @template const T
* @param {[T, T]} x
* @returns {T}
*/
function f4(x) {
return x[0];
}
const t9 = f4([[1, "x"], [2, "y"]]);
const t10 = f4([{ a: 1, b: "x" }, { a: 2, b: "y" }]);
/**
* @template const T
* @param {{ x: T, y: T}} obj
* @returns {T}
*/
function f5(obj) {
return obj.x;
}
const t11 = f5({ x: [1, "x"], y: [2, "y"] });
const t12 = f5({ x: { a: 1, b: "x" }, y: { a: 2, b: "y" } });
/**
* @template const T
*/
class C {
/**
* @param {T} x
*/
constructor(x) {}
/**
* @template const U
* @param {U} x
*/
foo(x) {
return x;
}
}
const t13 = new C({ a: 1, b: "c", d: ["e", 2, true, { f: "g" }] });
const t14 = t13.foo(["a", ["b", "c"]]);
/**
* @template {readonly unknown[]} const T
* @param {T} args
* @returns {T}
*/
function f6(...args) {
return args;
}
const t15 = f6(1, 'b', { a: 1, b: 'x' });
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTemplateTag7.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
// @Filename: a.js
/**
* @template const T
* @typedef {[T]} X
*/
/**
* @template const T
*/
class C { }
/**
* @template private T
* @param {T} x
* @returns {T}
*/
function f(x) {
return x;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTemplateTag8.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
// @Filename: a.js
/**
* @template out T
* @typedef {Object} Covariant
* @property {T} x
*/
/**
* @type {Covariant<unknown>}
*/
let super_covariant = { x: 1 };
/**
* @type {Covariant<string>}
*/
let sub_covariant = { x: '' };
super_covariant = sub_covariant;
sub_covariant = super_covariant; // Error
/**
* @template in T
* @typedef {Object} Contravariant
* @property {(x: T) => void} f
*/
/**
* @type {Contravariant<unknown>}
*/
let super_contravariant = { f: (x) => {} };
/**
* @type {Contravariant<string>}
*/
let sub_contravariant = { f: (x) => {} };
super_contravariant = sub_contravariant; // Error
sub_contravariant = super_contravariant;
/**
* @template in out T
* @typedef {Object} Invariant
* @property {(x: T) => T} f
*/
/**
* @type {Invariant<unknown>}
*/
let super_invariant = { f: (x) => {} };
/**
* @type {Invariant<string>}
*/
let sub_invariant = { f: (x) => { return "" } };
super_invariant = sub_invariant; // Error
sub_invariant = super_invariant; // Error
/**
* @template in T
* @param {T} x
*/
function f(x) {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTemplateTagDefault.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @declaration: true
// @outDir: out
// @Filename: file.js
/**
* @template {string | number} [T=string] - ok: defaults are permitted
* @typedef {[T]} A
*/
/** @type {A} */ // ok, default for `T` in `A` is `string`
const aDefault1 = [""];
/** @type {A} */ // error: `number` is not assignable to string`
const aDefault2 = [0];
/** @type {A<string>} */ // ok, `T` is provided for `A`
const aString = [""];
/** @type {A<number>} */ // ok, `T` is provided for `A`
const aNumber = [0];
/**
* @template T
* @template [U=T] - ok: default can reference earlier type parameter
* @typedef {[T, U]} B
*/
/**
* @template {string | number} [T] - error: default requires an `=type`
* @typedef {[T]} C
*/
/**
* @template {string | number} [T=] - error: default requires a `type`
* @typedef {[T]} D
*/
/**
* @template {string | number} [T=string]
* @template U - error: Required type parameters cannot follow optional type parameters
* @typedef {[T, U]} E
*/
/**
* @template [T=U] - error: Type parameter defaults can only reference previously declared type parameters.
* @template [U=T]
* @typedef {[T, U]} G
*/
/**
* @template T
* @template [U=T] - ok: default can reference earlier type parameter
* @param {T} a
* @param {U} b
*/
function f1(a, b) {}
/**
* @template {string | number} [T=string]
* @template U - error: Required type parameters cannot follow optional type parameters
* @param {T} a
* @param {U} b
*/
function f2(a, b) {}
/**
* @template [T=U] - error: Type parameter defaults can only reference previously declared type parameters.
* @template [U=T]
* @param {T} a
* @param {U} b
*/
function f3(a, b) {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTemplateTagNameResolution.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @outDir: out
// @declaration: true
// @Filename: file.js
/**
* @template T
* @template {keyof T} K
* @typedef {T[K]} Foo
*/
const x = { a: 1 };
/** @type {Foo<typeof x, "a">} */
const y = "a"; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocThisType.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @filename: /types.d.ts
export interface Foo {
foo: () => void;
}
export type M = (this: Foo) => void;
// @filename: /a.js
/** @type {import('./types').M} */
export const f1 = function() {
this.test();
}
/** @type {import('./types').M} */
export function f2() {
this.test();
}
/** @type {(this: import('./types').Foo) => void} */
export const f3 = function() {
this.test();
}
/** @type {(this: import('./types').Foo) => void} */
export function f4() {
this.test();
}
/** @type {function(this: import('./types').Foo): void} */
export const f5 = function() {
this.test();
}
/** @type {function(this: import('./types').Foo): void} */
export function f6() {
this.test();
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTwoLineTypedef.ts | TypeScript | // Regression from #18301
/**
* @typedef LoadCallback
* @type {function}
*/
type LoadCallback = void;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeDefAtStartOfFile.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: dtsEquivalent.js
/** @typedef {{[k: string]: any}} AnyEffect */
/** @typedef {number} Third */
// @Filename: index.js
/** @type {AnyEffect} */
let b;
/** @type {Third} */
let c;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeFromChainedAssignment.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @noImplicitAny: true
// @Filename: a.js
function A () {
this.x = 1
/** @type {1} */
this.first = this.second = 1
}
/** @param {number} n */
A.prototype.y = A.prototype.z = function f(n) {
return n + this.x
}
/** @param {number} m */
A.s = A.t = function g(m) {
return m + this.x
}
var a = new A()
a.y('no') // error
a.z('not really') // error
A.s('still no') // error
A.t('not here either') // error
a.first = 10 // error: '10' isn't assignable to '1'
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeFromChainedAssignment2.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @noImplicitAny: true
// @Filename: mod.js
/** @param {number} n */
exports.f = exports.g = function fg(n) {
return n + 1
}
/** @param {string} mom */
module.exports.h = module.exports.i = function hi(mom) {
return `hi, ${mom}!`;
}
// @Filename: use.js
var mod = require('./mod');
mod.f('no')
mod.g('also no')
mod.h(0)
mod.i(1)
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeFromChainedAssignment3.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: a.js
exports.wrapSync = exports.selectSeries = exports.selectLimit = exports.select = exports.foldr = exports.foldl = exports.inject = exports.forEachOfLimit = exports.forEachOfSeries = exports.forEachOf = exports.forEachLimit = exports.forEachSeries = exports.forEach = exports.findSeries = exports.findLimit = exports.find = exports.anySeries = exports.anyLimit = exports.any = exports.allSeries = exports.allLimit = exports.all = exports.whilst = exports.waterfall = exports.until = exports.unmemoize = exports.tryEach = exports.transform = exports.timesSeries = exports.timesLimit = exports.times = exports.timeout = exports.sortBy = exports.someSeries = exports.someLimit = exports.some = exports.setImmediate = exports.series = exports.seq = exports.retryable = exports.retry = exports.rejectSeries = exports.rejectLimit = exports.reject = exports.reflectAll = exports.reflect = exports.reduceRight = exports.reduce = exports.race = exports.queue = exports.priorityQueue = exports.parallelLimit = exports.parallel = exports.nextTick = exports.memoize = exports.mapValuesSeries = exports.mapValuesLimit = exports.mapValues = exports.mapSeries = exports.mapLimit = exports.map = exports.log = exports.groupBySeries = exports.groupByLimit = exports.groupBy = exports.forever = exports.filterSeries = exports.filterLimit = exports.filter = exports.everySeries = exports.everyLimit = exports.every = exports.ensureAsync = exports.eachSeries = exports.eachOfSeries = exports.eachOfLimit = exports.eachOf = exports.eachLimit = exports.each = exports.during = exports.doWhilst = exports.doUntil = exports.doDuring = exports.dir = exports.detectSeries = exports.detectLimit = exports.detect = exports.constant = exports.concatSeries = exports.concatLimit = exports.concat = exports.compose = exports.cargo = exports.autoInject = exports.auto = exports.asyncify = exports.applyEachSeries = exports.applyEach = exports.apply = undefined; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeReferenceExports.ts | TypeScript | // @allowJs: true
// @noEmit: true
// @checkJs: true
// @Filename: bug27342.js
module.exports = {}
/**
* @type {exports}
*/
var x
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeReferenceToImport.ts | TypeScript | // #34802
// @Filename: jsdocTypeReferenceToImport.js
// @noEmit: true
// @allowJs: true
// @checkJs: true
const C = require('./ex').C;
const D = require('./ex')?.C;
/** @type {C} c */
var c = new C()
c.start
c.end
/** @type {D} c */
var d = new D()
d.start
d.end
// @Filename: ex.d.ts
export class C {
start: number
end: number
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeReferenceToImportOfClassExpression.ts | TypeScript | // @noEmit: true
// @allowjs: true
// @checkjs: true
// @Filename: MW.js
/** @typedef {import("./MC")} MC */
class MW {
/**
* @param {MC} compiler the compiler
*/
constructor(compiler) {
this.compiler = compiler;
}
}
module.exports = MW;
// @Filename: MC.js
const MW = require("./MW");
/** @typedef {number} Cictema */
module.exports = class MC {
watch() {
return new MW(this);
}
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeReferenceToImportOfFunctionExpression.ts | TypeScript | // @noEmit: true
// @allowjs: true
// @checkjs: true
// @Filename: MW.js
/** @typedef {import("./MC")} MC */
class MW {
/**
* @param {MC} compiler the compiler
*/
constructor(compiler) {
this.compiler = compiler;
}
}
module.exports = MW;
// @Filename: MC.js
const MW = require("./MW");
/** @typedef {number} Meyerhauser */
/** @class */
module.exports = function MC() {
/** @type {any} */
var x = {}
return new MW(x);
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeReferenceToMergedClass.ts | TypeScript | // https://github.com/microsoft/TypeScript/issues/34685
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: jsdocTypeReferenceToMergedClass.js
var Workspace = {}
/** @type {Workspace.Project} */
var p;
p.isServiceProject()
Workspace.Project = function wp() { }
Workspace.Project.prototype = {
isServiceProject() {}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeReferenceToValue.ts | TypeScript | // @Filename: foo.js
// @noEmit: true
// @allowJs: true
// @checkJs: true
/** @param {Image} image */
function process(image) {
return new image(1, 1)
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeReferenceUseBeforeDef.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: bug25097.js
/** @type {C | null} */
const c = null
class C {
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeTag.ts | TypeScript | // @allowJS: true
// @suppressOutputPathCheck: true
// @strictNullChecks: true
// @filename: a.js
/** @type {String} */
var S;
/** @type {string} */
var s;
/** @type {Number} */
var N;
/** @type {number} */
var n;
/** @type {Boolean} */
var B;
/** @type {boolean} */
var b;
/** @type {Void} */
var V;
/** @type {void} */
var v;
/** @type {Undefined} */
var U;
/** @type {undefined} */
var u;
/** @type {Null} */
var Nl;
/** @type {null} */
var nl;
/** @type {Array} */
var A;
/** @type {array} */
var a;
/** @type {Promise} */
var P;
/** @type {promise} */
var p;
/** @type {?number} */
var nullable;
/** @type {Object} */
var Obj;
/** @type {object} */
var obj;
/** @type {Function} */
var Func;
/** @type {(s: string) => number} */
var f;
/** @type {new (s: string) => { s: string }} */
var ctor;
// @filename: b.ts
var S: string;
var s: string;
var N: number;
var n: number
var B: boolean;
var b: boolean;
var V :void;
var v: void;
var U: undefined;
var u: undefined;
var Nl: null;
var nl: null;
var A: any[];
var a: any[];
var P: Promise<any>;
var p: Promise<any>;
var nullable: number | null;
var Obj: any;
var obj: any;
var Func: Function;
var f: (s: string) => number;
var ctor: new (s: string) => { s: string };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeTagCast.ts | TypeScript | // @allowJS: true
// @suppressOutputPathCheck: true
// @strictNullChecks: true
// @filename: a.ts
var W: string;
// @filename: b.js
// @ts-check
var W = /** @type {string} */(/** @type {*} */ (4));
var W = /** @type {string} */(4); // Error
/** @type {*} */
var a;
/** @type {string} */
var s;
var a = /** @type {*} */("" + 4);
var s = "" + /** @type {*} */(4);
class SomeBase {
constructor() {
this.p = 42;
}
}
class SomeDerived extends SomeBase {
constructor() {
super();
this.x = 42;
}
}
class SomeOther {
constructor() {
this.q = 42;
}
}
function SomeFakeClass() {
/** @type {string|number} */
this.p = "bar";
}
// Type assertion should check for assignability in either direction
var someBase = new SomeBase();
var someDerived = new SomeDerived();
var someOther = new SomeOther();
var someFakeClass = new SomeFakeClass();
someBase = /** @type {SomeBase} */(someDerived);
someBase = /** @type {SomeBase} */(someBase);
someBase = /** @type {SomeBase} */(someOther); // Error
someDerived = /** @type {SomeDerived} */(someDerived);
someDerived = /** @type {SomeDerived} */(someBase);
someDerived = /** @type {SomeDerived} */(someOther); // Error
someOther = /** @type {SomeOther} */(someDerived); // Error
someOther = /** @type {SomeOther} */(someBase); // Error
someOther = /** @type {SomeOther} */(someOther);
someFakeClass = someBase;
someFakeClass = someDerived;
someBase = someFakeClass; // Error
someBase = /** @type {SomeBase} */(someFakeClass);
// Type assertion cannot be a type-predicate type
/** @type {number | string} */
var numOrStr;
/** @type {string} */
var str;
if(/** @type {numOrStr is string} */(numOrStr === undefined)) { // Error
str = numOrStr; // Error, no narrowing occurred
}
var asConst1 = /** @type {const} */(1);
var asConst2 = /** @type {const} */({
x: 1
}); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeTagParameterType.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strict: true
// @noImplicitAny: true
// @Filename: a.js
/** @type {function(string): void} */
const f = (value) => {
value = 1 // should error
};
/** @type {(s: string) => void} */
function g(s) {
s = 1 // Should error
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocTypeTagRequiredParameters.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strict: true
// @noImplicitAny: true
// @Filename: a.js
/** @type {function(string): void} */
const f = (value) => {
};
/** @type {(s: string) => void} */
function g(s) {
}
/** @type {{(s: string): void}} */
function h(s) {
}
f() // should error
g() // should error
h()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocVariableDeclarationWithTypeAnnotation.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @target: esnext
// @noImplicitAny: true
// @outDir: out
// @Filename: foo.js
/** @type {boolean} */
var /** @type {string} */ x,
/** @type {number} */ y;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsdocVariadicType.ts | TypeScript | // @allowJS: true
// @checkJs: true
// @noEmit: true
// @filename: a.js
/**
* @type {function(boolean, string, ...*):void}
*/
const foo = function (a, b, ...r) { };
// @filename: b.ts
foo(false, '');
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsxCheckJsxNoTypeArgumentsAllowed.tsx | TypeScript (TSX) | // @jsx: preserve
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
// @allowJs: true
// @outDir: ./out
// @checkJs: true
// @filename: component.d.ts
import * as React from "react";
export declare class MyComp<P> extends React.Component<P, {}> {
internalProp: P;
}
export interface Prop {
a: number,
b: string
}
// @filename: file.jsx
import { MyComp, Prop } from "./component";
import * as React from "react";
let x = <MyComp<Prop> a={10} b="hi" />; // error, no type arguments in js
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsxJsxsCjsTransformChildren.tsx | TypeScript (TSX) | // @jsx: react-jsx,react-jsxdev
// @strict: true
// @module: commonjs
/// <reference path="/.lib/react16.d.ts" />
const a = <div>text</div>;
export {};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsxJsxsCjsTransformCustomImport.tsx | TypeScript (TSX) | // @jsx: react-jsx,react-jsxdev
// @jsxImportSource: preact
// @strict: true
// @module: commonjs
/// <reference path="/.lib/react16.d.ts" />
const a = <>
<p></p>
text
<div className="foo"></div>
</>
export {}; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsxJsxsCjsTransformCustomImportPragma.tsx | TypeScript (TSX) | // @jsx: react-jsx,react-jsxdev
// @strict: true
// @module: commonjs
// @filename: preact.tsx
/// <reference path="/.lib/react16.d.ts" />
/* @jsxImportSource preact */
const a = <>
<p></p>
text
<div className="foo"></div>
</>
export {};
// @filename: react.tsx
/// <reference path="/.lib/react16.d.ts" />
/* @jsxImportSource react */
import "./preact";
const a = <>
<p></p>
text
<div className="foo"></div>
</>
export {}; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsxJsxsCjsTransformKeyProp.tsx | TypeScript (TSX) | // @jsx: react-jsx,react-jsxdev
// @strict: true
// @module: commonjs
/// <reference path="/.lib/react16.d.ts" />
const props = { answer: 42 }
const a = <div key="foo" {...props}>text</div>;
const b = <div {...props} key="bar">text</div>;
export {};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsxJsxsCjsTransformKeyPropCustomImport.tsx | TypeScript (TSX) | // @jsx: react-jsx,react-jsxdev
// @jsxImportSource: preact
// @strict: true
// @module: commonjs
/// <reference path="/.lib/react16.d.ts" />
const props = { answer: 42 }
const a = <div key="foo" {...props}>text</div>;
const b = <div {...props} key="bar">text</div>;
export {};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsxJsxsCjsTransformKeyPropCustomImportPragma.tsx | TypeScript (TSX) | // @jsx: react-jsx,react-jsxdev
// @strict: true
// @module: commonjs
// @filename: preact.tsx
/// <reference path="/.lib/react16.d.ts" />
/* @jsxImportSource preact */
const props = { answer: 42 }
const a = <div key="foo" {...props}>text</div>;
const b = <div {...props} key="bar">text</div>;
export {};
// @filename: react.tsx
/// <reference path="/.lib/react16.d.ts" />
/* @jsxImportSource react */
import "./preact";
const props2 = { answer: 42 }
const a2 = <div key="foo" {...props2}>text</div>;
const b2 = <div {...props2} key="bar">text</div>;
export {};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsxJsxsCjsTransformNestedSelfClosingChild.tsx | TypeScript (TSX) | // @jsx: react-jsx,react-jsxdev
// @strict: true
// @module: commonjs
/// <reference path="/.lib/react16.d.ts" />
import type * as React from 'react';
console.log(
<div>
<div />
</div>
)
console.log(
<div>
<div />
<div />
</div>
)
console.log(
<div>
{[1, 2].map(i => <div key={i}>{i}</div>)}
</div>
) | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsxJsxsCjsTransformSubstitutesNames.tsx | TypeScript (TSX) | // @jsx: react-jsx,react-jsxdev
// @strict: true
// @module: commonjs
/// <reference path="/.lib/react16.d.ts" />
const a = <div></div>
export {}; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsxJsxsCjsTransformSubstitutesNamesFragment.tsx | TypeScript (TSX) | // @jsx: react-jsx,react-jsxdev
// @strict: true
// @module: commonjs
/// <reference path="/.lib/react16.d.ts" />
const a = <>
<p></p>
text
<div></div>
</>
export {}; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsxParsingError4.tsx | TypeScript (TSX) | // @strict: true, false
// @jsx: react
// @filename: a.tsx
declare const React: any
declare namespace JSX {
interface IntrinsicElements {
[k: string]: any
}
}
const a = (
<public-foo></public-foo>
);
const b = (
<public></public>
);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsxReactTestSuite.tsx | TypeScript (TSX) | // @jsx: preserve
declare var React: any;
declare var Component:any;
declare var Composite:any;
declare var Composite2:any;
declare var Child:any;
declare var Namespace:any;
declare var foo: any;
declare var bar: any;
declare var y:any;
declare var x:any;
declare var z:any;
declare var hasOwnProperty:any;
<div>text</div>;
<div>
{this.props.children}
</div>;
<div>
<div><br /></div>
<Component>{foo}<br />{bar}</Component>
<br />
</div>;
<Composite>
{this.props.children}
</Composite>;
<Composite>
<Composite2 />
</Composite>;
var x =
<div
attr1={
"foo" + "bar"
}
attr2={
"foo" + "bar" +
"baz" + "bug"
}
attr3={
"foo" + "bar" +
"baz" + "bug"
// Extra line here.
}
attr4="baz">
</div>;
(
<div>
{/* A comment at the beginning */}
{/* A second comment at the beginning */}
<span>
{/* A nested comment */}
</span>
{/* A sandwiched comment */}
<br />
{/* A comment at the end */}
{/* A second comment at the end */}
</div>
);
(
<div
/* a multi-line
comment */
attr1="foo">
<span // a double-slash comment
attr2="bar"
/>
</div>
);
<div> </div>;
<div> </div>;
<hasOwnProperty>testing</hasOwnProperty>;
<Component constructor="foo" />;
<Namespace.Component />;
<Namespace.DeepNamespace.Component />;
<Component { ... x } y
={2 } z />;
<Component
{...this.props} sound="moo" />;
<font-face />;
<Component x={y} />;
<x-component />;
<Component {...x} />;
<Component { ...x } y={2} />;
<Component { ... x } y={2} z />;
<Component x={1} {...y} />;
<Component x={1} y="2" {...z} {...z}><Child /></Component>;
<Component x="1" {...(z = { y: 2 }, z)} z={3}>Text</Component>;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/jsxSpreadOverwritesAttributeStrict.tsx | TypeScript (TSX) | // @filename: file.tsx
// @jsx: preserve
// @strict: true
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
interface Props {
a: number;
b: number;
c?: number;
d?: number;
}
const props: Props = { a: 1, b: 1 };
const Foo = (props: Props) => <div>{ props.a }</div>;
// ok
const a1 = <Foo {...props}></Foo>;
const a2 = <Foo d={1} {...props}></Foo>;
// error
const b1 = <Foo a={1} {...props}></Foo>;
const b2 = <Foo a={1} b={2} {...props}></Foo>;
const b3 = <Foo a={1} d={1} {...props} {...{ d: 1 }}></Foo>;
const b4 = <Foo a={1} d={1} {...props} {...{ a: 1, d: 1 }}></Foo>;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/keyofAndForIn.ts | TypeScript | // @declaration: true
// Repro from #12513
function f1<K extends string, T>(obj: { [P in K]: T }, k: K) {
const b = k in obj;
let k1: K;
for (k1 in obj) {
let x1 = obj[k1];
}
for (let k2 in obj) {
let x2 = obj[k2];
}
}
function f2<T>(obj: { [P in keyof T]: T[P] }, k: keyof T) {
const b = k in obj;
let k1: keyof T;
for (k1 in obj) {
let x1 = obj[k1];
}
for (let k2 in obj) {
let x2 = obj[k2];
}
}
function f3<T, K extends keyof T>(obj: { [P in K]: T[P] }, k: K) {
const b = k in obj;
let k1: K;
for (k1 in obj) {
let x1 = obj[k1];
}
for (let k2 in obj) {
let x2 = obj[k2];
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/keyofAndIndexedAccess.ts | TypeScript | // @strictNullChecks: true
// @declaration: true
class Shape {
name: string;
width: number;
height: number;
visible: boolean;
}
class TaggedShape extends Shape {
tag: string;
}
class Item {
name: string;
price: number;
}
class Options {
visible: "yes" | "no";
}
type Dictionary<T> = { [x: string]: T };
type NumericallyIndexed<T> = { [x: number]: T };
const enum E { A, B, C }
type K00 = keyof any; // string
type K01 = keyof string; // "toString" | "charAt" | ...
type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ...
type K03 = keyof boolean; // "valueOf"
type K04 = keyof void; // never
type K05 = keyof undefined; // never
type K06 = keyof null; // never
type K07 = keyof never; // string | number | symbol
type K08 = keyof unknown; // never
type K10 = keyof Shape; // "name" | "width" | "height" | "visible"
type K11 = keyof Shape[]; // "length" | "toString" | ...
type K12 = keyof Dictionary<Shape>; // string
type K13 = keyof {}; // never
type K14 = keyof Object; // "constructor" | "toString" | ...
type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ...
type K16 = keyof [string, number]; // "0" | "1" | "length" | "toString" | ...
type K17 = keyof (Shape | Item); // "name"
type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price"
type K19 = keyof NumericallyIndexed<Shape> // never
type KeyOf<T> = keyof T;
type K20 = KeyOf<Shape>; // "name" | "width" | "height" | "visible"
type K21 = KeyOf<Dictionary<Shape>>; // string
type NAME = "name";
type WIDTH_OR_HEIGHT = "width" | "height";
type Q10 = Shape["name"]; // string
type Q11 = Shape["width" | "height"]; // number
type Q12 = Shape["name" | "visible"]; // string | boolean
type Q20 = Shape[NAME]; // string
type Q21 = Shape[WIDTH_OR_HEIGHT]; // number
type Q30 = [string, number][0]; // string
type Q31 = [string, number][1]; // number
type Q32 = [string, number][number]; // string | number
type Q33 = [string, number][E.A]; // string
type Q34 = [string, number][E.B]; // number
type Q35 = [string, number]["0"]; // string
type Q36 = [string, number]["1"]; // string
type Q40 = (Shape | Options)["visible"]; // boolean | "yes" | "no"
type Q41 = (Shape & Options)["visible"]; // true & "yes" | true & "no" | false & "yes" | false & "no"
type Q50 = Dictionary<Shape>["howdy"]; // Shape
type Q51 = Dictionary<Shape>[123]; // Shape
type Q52 = Dictionary<Shape>[E.B]; // Shape
declare let cond: boolean;
function getProperty<T, K extends keyof T>(obj: T, key: K) {
return obj[key];
}
function setProperty<T, K extends keyof T>(obj: T, key: K, value: T[K]) {
obj[key] = value;
}
function f10(shape: Shape) {
let name = getProperty(shape, "name"); // string
let widthOrHeight = getProperty(shape, cond ? "width" : "height"); // number
let nameOrVisible = getProperty(shape, cond ? "name" : "visible"); // string | boolean
setProperty(shape, "name", "rectangle");
setProperty(shape, cond ? "width" : "height", 10);
setProperty(shape, cond ? "name" : "visible", true); // Technically not safe
}
function f11(a: Shape[]) {
let len = getProperty(a, "length"); // number
setProperty(a, "length", len);
}
function f12(t: [Shape, boolean]) {
let len = getProperty(t, "length");
let s2 = getProperty(t, "0"); // Shape
let b2 = getProperty(t, "1"); // boolean
}
function f13(foo: any, bar: any) {
let x = getProperty(foo, "x"); // any
let y = getProperty(foo, "100"); // any
let z = getProperty(foo, bar); // any
}
class Component<PropType> {
props: PropType;
getProperty<K extends keyof PropType>(key: K) {
return this.props[key];
}
setProperty<K extends keyof PropType>(key: K, value: PropType[K]) {
this.props[key] = value;
}
}
function f20(component: Component<Shape>) {
let name = component.getProperty("name"); // string
let widthOrHeight = component.getProperty(cond ? "width" : "height"); // number
let nameOrVisible = component.getProperty(cond ? "name" : "visible"); // string | boolean
component.setProperty("name", "rectangle");
component.setProperty(cond ? "width" : "height", 10)
component.setProperty(cond ? "name" : "visible", true); // Technically not safe
}
function pluck<T, K extends keyof T>(array: T[], key: K) {
return array.map(x => x[key]);
}
function f30(shapes: Shape[]) {
let names = pluck(shapes, "name"); // string[]
let widths = pluck(shapes, "width"); // number[]
let nameOrVisibles = pluck(shapes, cond ? "name" : "visible"); // (string | boolean)[]
}
function f31<K extends keyof Shape>(key: K) {
const shape: Shape = { name: "foo", width: 5, height: 10, visible: true };
return shape[key]; // Shape[K]
}
function f32<K extends "width" | "height">(key: K) {
const shape: Shape = { name: "foo", width: 5, height: 10, visible: true };
return shape[key]; // Shape[K]
}
function f33<S extends Shape, K extends keyof S>(shape: S, key: K) {
let name = getProperty(shape, "name");
let prop = getProperty(shape, key);
return prop;
}
function f34(ts: TaggedShape) {
let tag1 = f33(ts, "tag");
let tag2 = getProperty(ts, "tag");
}
class C {
public x: string;
protected y: string;
private z: string;
}
// Indexed access expressions have always permitted access to private and protected members.
// For consistency we also permit such access in indexed access types.
function f40(c: C) {
type X = C["x"];
type Y = C["y"];
type Z = C["z"];
let x: X = c["x"];
let y: Y = c["y"];
let z: Z = c["z"];
}
function f50<T>(k: keyof T, s: string) {
const x1 = s as keyof T;
const x2 = k as string;
}
function f51<T, K extends keyof T>(k: K, s: string) {
const x1 = s as keyof T;
const x2 = k as string;
}
function f52<T>(obj: { [x: string]: boolean }, k: Exclude<keyof T, symbol>, s: string, n: number) {
const x1 = obj[s];
const x2 = obj[n];
const x3 = obj[k];
}
function f53<T, K extends Exclude<keyof T, symbol>>(obj: { [x: string]: boolean }, k: K, s: string, n: number) {
const x1 = obj[s];
const x2 = obj[n];
const x3 = obj[k];
}
function f54<T>(obj: T, key: keyof T) {
for (let s in obj[key]) {
}
const b = "foo" in obj[key];
}
function f55<T, K extends keyof T>(obj: T, key: K) {
for (let s in obj[key]) {
}
const b = "foo" in obj[key];
}
function f60<T>(source: T, target: T) {
for (let k in source) {
target[k] = source[k];
}
}
function f70(func: <T, U>(k1: keyof (T | U), k2: keyof (T & U)) => void) {
func<{ a: any, b: any }, { a: any, c: any }>('a', 'a');
func<{ a: any, b: any }, { a: any, c: any }>('a', 'b');
func<{ a: any, b: any }, { a: any, c: any }>('a', 'c');
}
function f71(func: <T, U>(x: T, y: U) => Partial<T & U>) {
let x = func({ a: 1, b: "hello" }, { c: true });
x.a; // number | undefined
x.b; // string | undefined
x.c; // boolean | undefined
}
function f72(func: <T, U, K extends keyof T | keyof U>(x: T, y: U, k: K) => (T & U)[K]) {
let a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number
let b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string
let c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean
}
function f73(func: <T, U, K extends keyof (T & U)>(x: T, y: U, k: K) => (T & U)[K]) {
let a = func({ a: 1, b: "hello" }, { c: true }, 'a'); // number
let b = func({ a: 1, b: "hello" }, { c: true }, 'b'); // string
let c = func({ a: 1, b: "hello" }, { c: true }, 'c'); // boolean
}
function f74(func: <T, U, K extends keyof (T | U)>(x: T, y: U, k: K) => (T | U)[K]) {
let a = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'a'); // number
let b = func({ a: 1, b: "hello" }, { a: 2, b: true }, 'b'); // string | boolean
}
function f80<T extends { a: { x: any } }>(obj: T) {
let a1 = obj.a; // { x: any }
let a2 = obj['a']; // { x: any }
let a3 = obj['a'] as T['a']; // T["a"]
let x1 = obj.a.x; // any
let x2 = obj['a']['x']; // any
let x3 = obj['a']['x'] as T['a']['x']; // T["a"]["x"]
}
function f81<T extends { a: { x: any } }>(obj: T) {
return obj['a']['x'] as T['a']['x'];
}
function f82() {
let x1 = f81({ a: { x: "hello" } }); // string
let x2 = f81({ a: { x: 42 } }); // number
}
function f83<T extends { [x: string]: { x: any } }, K extends keyof T>(obj: T, key: K) {
return obj[key]['x'] as T[K]['x'];
}
function f84() {
let x1 = f83({ foo: { x: "hello" } }, "foo"); // string
let x2 = f83({ bar: { x: 42 } }, "bar"); // number
}
class C1 {
x: number;
get<K extends keyof this>(key: K) {
return this[key];
}
set<K extends keyof this>(key: K, value: this[K]) {
this[key] = value;
}
foo() {
let x1 = this.x; // number
let x2 = this["x"]; // number
let x3 = this.get("x"); // this["x"]
let x4 = getProperty(this, "x"); // this["x"]
this.x = 42;
this["x"] = 42;
this.set("x", 42);
setProperty(this, "x", 42);
}
}
type S2 = {
a: string;
b: string;
};
function f90<T extends S2, K extends keyof S2>(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K]) {
x1 = x2;
x1 = x3;
x2 = x1;
x2 = x3;
x3 = x1;
x3 = x2;
x1.length;
x2.length;
x3.length;
}
function f91<T, K extends keyof T>(x: T, y: T[keyof T], z: T[K]) {
let a: {};
a = x;
a = y;
a = z;
}
function f92<T, K extends keyof T>(x: T, y: T[keyof T], z: T[K]) {
let a: {} | null | undefined;
a = x;
a = y;
a = z;
}
// Repros from #12011
class Base {
get<K extends keyof this>(prop: K) {
return this[prop];
}
set<K extends keyof this>(prop: K, value: this[K]) {
this[prop] = value;
}
}
class Person extends Base {
parts: number;
constructor(parts: number) {
super();
this.set("parts", parts);
}
getParts() {
return this.get("parts")
}
}
class OtherPerson {
parts: number;
constructor(parts: number) {
setProperty(this, "parts", parts);
}
getParts() {
return getProperty(this, "parts")
}
}
// Modified repro from #12544
function path<T, K1 extends keyof T>(obj: T, key1: K1): T[K1];
function path<T, K1 extends keyof T, K2 extends keyof T[K1]>(obj: T, key1: K1, key2: K2): T[K1][K2];
function path<T, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(obj: T, key1: K1, key2: K2, key3: K3): T[K1][K2][K3];
function path(obj: any, ...keys: (string | number)[]): any;
function path(obj: any, ...keys: (string | number)[]): any {
let result = obj;
for (let k of keys) {
result = result[k];
}
return result;
}
type Thing = {
a: { x: number, y: string },
b: boolean
};
function f1(thing: Thing) {
let x1 = path(thing, 'a'); // { x: number, y: string }
let x2 = path(thing, 'a', 'y'); // string
let x3 = path(thing, 'b'); // boolean
let x4 = path(thing, ...['a', 'x']); // any
}
// Repro from comment in #12114
const assignTo2 = <T, K1 extends keyof T, K2 extends keyof T[K1]>(object: T, key1: K1, key2: K2) =>
(value: T[K1][K2]) => object[key1][key2] = value;
// Modified repro from #12573
declare function one<T>(handler: (t: T) => void): T
var empty = one(() => {}) // inferred as {}, expected
type Handlers<T> = { [K in keyof T]: (t: T[K]) => void }
declare function on<T>(handlerHash: Handlers<T>): T
var hashOfEmpty1 = on({ test: () => {} }); // {}
var hashOfEmpty2 = on({ test: (x: boolean) => {} }); // { test: boolean }
// Repro from #12624
interface Options1<Data, Computed> {
data?: Data
computed?: Computed;
}
declare class Component1<Data, Computed> {
constructor(options: Options1<Data, Computed>);
get<K extends keyof (Data & Computed)>(key: K): (Data & Computed)[K];
}
let c1 = new Component1({
data: {
hello: ""
}
});
c1.get("hello");
// Repro from #12625
interface Options2<Data, Computed> {
data?: Data
computed?: Computed;
}
declare class Component2<Data, Computed> {
constructor(options: Options2<Data, Computed>);
get<K extends keyof Data | keyof Computed>(key: K): (Data & Computed)[K];
}
// Repro from #12641
interface R {
p: number;
}
function f<K extends keyof R>(p: K) {
let a: any;
a[p].add; // any
}
// Repro from #12651
type MethodDescriptor = {
name: string;
args: any[];
returnValue: any;
}
declare function dispatchMethod<M extends MethodDescriptor>(name: M['name'], args: M['args']): M['returnValue'];
type SomeMethodDescriptor = {
name: "someMethod";
args: [string, number];
returnValue: string[];
}
let result = dispatchMethod<SomeMethodDescriptor>("someMethod", ["hello", 35]);
// Repro from #13073
type KeyTypes = "a" | "b"
let MyThingy: { [key in KeyTypes]: string[] };
function addToMyThingy<S extends KeyTypes>(key: S) {
MyThingy[key].push("a");
}
// Repro from #13102
type Handler<T> = {
onChange: (name: keyof T) => void;
};
function onChangeGenericFunction<T>(handler: Handler<T & {preset: number}>) {
handler.onChange('preset')
}
// Repro from #13285
function updateIds<T extends Record<K, string>, K extends string>(
obj: T,
idFields: K[],
idMapping: Partial<Record<T[K], T[K]>>
): Record<K, string> {
for (const idField of idFields) {
const newId: T[K] | undefined = idMapping[obj[idField]];
if (newId) {
obj[idField] = newId;
}
}
return obj;
}
// Repro from #13285
function updateIds2<T extends { [x: string]: string }, K extends keyof T>(
obj: T,
key: K,
stringMap: { [oldId: string]: string }
) {
var x = obj[key];
stringMap[x]; // Should be OK.
}
// Repro from #13514
declare function head<T extends Array<any>>(list: T): T[0];
// Repro from #13604
class A<T> {
props: T & { foo: string };
}
class B extends A<{ x: number}> {
f(p: this["props"]) {
p.x;
}
}
// Repro from #13749
class Form<T> {
private childFormFactories: {[K in keyof T]: (v: T[K]) => Form<T[K]>}
public set<K extends keyof T>(prop: K, value: T[K]) {
this.childFormFactories[prop](value)
}
}
// Repro from #13787
class SampleClass<P> {
public props: Readonly<P>;
constructor(props: P) {
this.props = Object.freeze(props);
}
}
interface Foo {
foo: string;
}
declare function merge<T, U>(obj1: T, obj2: U): T & U;
class AnotherSampleClass<T> extends SampleClass<T & Foo> {
constructor(props: T) {
const foo: Foo = { foo: "bar" };
super(merge(props, foo));
}
public brokenMethod() {
this.props.foo.concat;
}
}
new AnotherSampleClass({});
// Positive repro from #17166
function f3<T, K extends Extract<keyof T, string>>(t: T, k: K, tk: T[K]): void {
for (let key in t) {
key = k // ok, K ==> keyof T
t[key] = tk; // ok, T[K] ==> T[keyof T]
}
}
// # 21185
type Predicates<TaggedRecord> = {
[T in keyof TaggedRecord]: (variant: TaggedRecord[keyof TaggedRecord]) => variant is TaggedRecord[T]
}
// Repros from #23592
type Example<T extends { [K in keyof T]: { prop: any } }> = { [K in keyof T]: T[K]["prop"] };
type Result = Example<{ a: { prop: string }; b: { prop: number } }>;
type Helper2<T> = { [K in keyof T]: Extract<T[K], { prop: any }> };
type Example2<T> = { [K in keyof Helper2<T>]: Helper2<T>[K]["prop"] };
type Result2 = Example2<{ 1: { prop: string }; 2: { prop: number } }>;
// Repro from #23618
type DBBoolTable<K extends string> = { [k in K]: 0 | 1 }
enum Flag {
FLAG_1 = "flag_1",
FLAG_2 = "flag_2"
}
type SimpleDBRecord<Flag extends string> = { staticField: number } & DBBoolTable<Flag>
function getFlagsFromSimpleRecord<Flag extends string>(record: SimpleDBRecord<Flag>, flags: Flag[]) {
return record[flags[0]];
}
type DynamicDBRecord<Flag extends string> = ({ dynamicField: number } | { dynamicField: string }) & DBBoolTable<Flag>
function getFlagsFromDynamicRecord<Flag extends string>(record: DynamicDBRecord<Flag>, flags: Flag[]) {
return record[flags[0]];
}
// Repro from #21368
interface I {
foo: string;
}
declare function take<T>(p: T): void;
function fn<T extends I, K extends keyof T>(o: T, k: K) {
take<{} | null | undefined>(o[k]);
take<any>(o[k]);
}
// Repro from #23133
class Unbounded<T> {
foo(x: T[keyof T]) {
let y: {} | undefined | null = x;
}
}
// Repro from #23940
interface I7 {
x: any;
}
type Foo7<T extends number> = T;
declare function f7<K extends keyof I7>(type: K): Foo7<I7[K]>;
// Repro from #21770
type Dict<T extends string> = { [key in T]: number };
type DictDict<V extends string, T extends string> = { [key in V]: Dict<T> };
function ff1<V extends string, T extends string>(dd: DictDict<V, T>, k1: V, k2: T): number {
return dd[k1][k2];
}
function ff2<V extends string, T extends string>(dd: DictDict<V, T>, k1: V, k2: T): number {
const d: Dict<T> = dd[k1];
return d[k2];
}
// Repro from #26409
const cf1 = <T extends { [P in K]: string; } & { cool: string; }, K extends keyof T>(t: T, k: K) =>
{
const s: string = t[k];
t.cool;
};
const cf2 = <T extends { [P in K | "cool"]: string; }, K extends keyof T>(t: T, k: K) =>
{
const s: string = t[k];
t.cool;
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/keyofAndIndexedAccess2.ts | TypeScript | // @strict: true
// @target: esnext
function f1(obj: { a: number, b: 0 | 1, c: string }, k0: 'a', k1: 'a' | 'b', k2: 'a' | 'b' | 'c') {
obj[k0] = 1;
obj[k0] = 2;
obj[k0] = 'x'; // Error
obj[k1] = 1;
obj[k1] = 2; // Error
obj[k1] = 'x'; // Error
obj[k2] = 1; // Error
obj[k2] = 2; // Error
obj[k2] = 'x'; // Error
}
function f2<T extends { [key: string]: number }>(a: { x: number, y: number }, b: { [key: string]: number }, c: T, k: keyof T) {
a = b; // Error, index signature in source doesn't imply properties are present
a = c; // Error, index signature in source doesn't imply properties are present
b = a;
b = c;
c = a; // Error, constraint on target doesn't imply any properties or signatures
c = b; // Error, constraint on target doesn't imply any properties or signatures
a.x;
b.x;
c.x;
c[k];
a.x = 1;
b.x = 1;
c.x = 1; // Error, cannot write to index signature through constraint
c[k] = 1; // Error, cannot write to index signature through constraint
}
function f3<K extends string>(a: { [P in K]: number }, b: { [key: string]: number }, k: K) {
a = b; // Error, index signature doesn't imply properties are present
b = a;
a[k];
a[k] = 1;
}
function f3b<K extends string>(a: { [P in K]: number }, b: { [P in string]: number }, k: K) {
a = b; // Error, index signature doesn't imply properties are present
b = a;
}
function f4<K extends string>(a: { [key: string]: number }[K], b: number) {
a = b;
b = a;
}
type Item = { a: string, b: number };
function f10<T extends Item, K extends keyof T>(obj: T, k1: string, k2: keyof Item, k3: keyof T, k4: K) {
obj[k1] = 123; // Error
obj[k2] = 123; // Error
obj[k3] = 123; // Error
obj[k4] = 123; // Error
}
type Dict = Record<string, number>;
function f11<K extends keyof Dict>(obj: Dict, k1: keyof Dict, k2: K) {
obj.foo = 123;
obj[k1] = 123;
obj[k2] = 123;
}
function f12<T extends Readonly<Dict>, K extends keyof T>(obj: T, k1: keyof Dict, k2: keyof T, k3: K) {
obj.foo = 123; // Error
obj[k1] = 123; // Error
obj[k2] = 123; // Error
obj[k3] = 123; // Error
}
// Repro from #27895
export interface Entity {
id: number | string;
}
export type IdOf<E extends Entity> = E['id'];
export interface EntityState<E extends Entity> {
ids: IdOf<E>[];
entities: { [key: string]: E, [key: number]: E };
}
export function getAllEntities<E extends Entity>(state: EntityState<E>): E[] {
const { ids, entities } = state;
return ids.map(id => entities[id]);
}
export function getEntity<E extends Entity>(id: IdOf<E>, state: EntityState<E>): E | undefined {
const { ids, entities } = state;
if (!ids.includes(id)) {
return undefined;
}
return entities[id];
}
// Repro from #30603
interface Type {
a: 123;
b: "some string";
}
function get123<K extends keyof Type>(): Type[K] {
return 123; // Error
}
// Repro from #30920
type StrictExtract<T, U> = T extends U ? U extends T ? T : never : never;
type StrictExclude<T, U> = T extends StrictExtract<T, U> ? never : T;
type A<T> = { [Q in { [P in keyof T]: P; }[keyof T]]: T[Q]; };
type B<T, V> = A<{ [Q in keyof T]: StrictExclude<B<T[Q], V>, {}>; }>;
// Repros from #30938
function fn<T extends {elements: Array<string>} | {elements: Array<number>}>(param: T, cb: (element: T['elements'][number]) => void) {
cb(param.elements[0]);
}
function fn2<T extends Array<string>>(param: T, cb: (element: T[number]) => void) {
cb(param[0]);
}
// Repro from #31149
function fn3<T extends ReadonlyArray<string>>(param: T, cb: (element: T[number]) => void) {
cb(param[0]);
}
function fn4<K extends number>() {
let x: Array<string>[K] = 'abc';
let y: ReadonlyArray<string>[K] = 'abc';
}
// Repro from #31439 and #31691
export class c {
[x: string]: string;
constructor() {
this.a = "b";
this["a"] = "b";
}
}
// Repro from #31385
type Foo<T> = { [key: string]: { [K in keyof T]: K }[keyof T] };
type Bar<T> = { [key: string]: { [K in keyof T]: [K] }[keyof T] };
type Baz<T, Q extends Foo<T>> = { [K in keyof Q]: T[Q[K]] };
type Qux<T, Q extends Bar<T>> = { [K in keyof Q]: T[Q[K]["0"]] };
// Repro from #32038
const actions = ['resizeTo', 'resizeBy'] as const;
for (const action of actions) {
window[action] = (x, y) => {
window[action](x, y);
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/keyofAndIndexedAccessErrors.ts | TypeScript | class Shape {
name: string;
width: number;
height: number;
visible: boolean;
}
type Dictionary<T> = { [x: string]: T };
type T00 = keyof K0; // Error
type T01 = keyof Object;
type T02 = keyof keyof Object;
type T03 = keyof keyof keyof Object;
type T04 = keyof keyof keyof keyof Object;
type T05 = keyof keyof keyof keyof keyof Object;
type T06 = keyof keyof keyof keyof keyof keyof Object;
type T10 = Shape["name"];
type T11 = Shape["foo"]; // Error
type T12 = Shape["name" | "foo"]; // Error
type T13 = Shape[any]; // Error
type T14 = Shape[string]; // Error
type T15 = Shape[number]; // Error
type T16 = Shape[boolean]; // Error
type T17 = Shape[void]; // Error
type T18 = Shape[undefined]; // Error
type T19 = Shape[{ x: string }]; // Error
type T20 = Shape[string | number]; // Error
type T21 = Shape[string & number];
type T22 = Shape[string | boolean]; // Error
type T30 = string[]["length"];
type T31 = string[][number];
type T32 = string[][string]; // Error
type T33 = string[][boolean]; // Error
type T40 = Dictionary<string>[any];
type T41 = Dictionary<string>[number];
type T42 = Dictionary<string>[string];
type T43 = Dictionary<string>[boolean]; // Error
type T50 = any[any];
type T51 = any[number];
type T52 = any[string];
type T53 = any[boolean]; // Error
type T60 = {}["toString"];
type T61 = []["toString"];
declare let cond: boolean;
function getProperty<T, K extends keyof T>(obj: T, key: K) {
return obj[key];
}
function setProperty<T, K extends keyof T>(obj: T, key: K, value: T[K]) {
obj[key] = value;
}
function f10(shape: Shape) {
let x1 = getProperty(shape, "name");
let x2 = getProperty(shape, "size"); // Error
let x3 = getProperty(shape, cond ? "name" : "size"); // Error
setProperty(shape, "name", "rectangle");
setProperty(shape, "size", 10); // Error
setProperty(shape, cond ? "name" : "size", 10); // Error
}
function f20<T, U>(x: T | U, y: T & U, k1: keyof (T | U), k2: keyof T & keyof U, k3: keyof (T & U), k4: keyof T | keyof U) {
x[k1];
x[k2];
x[k3]; // Error
x[k4]; // Error
y[k1];
y[k2];
y[k3];
y[k4];
k1 = k2;
k1 = k3; // Error
k1 = k4; // Error
k2 = k1;
k2 = k3; // Error
k2 = k4; // Error
k3 = k1;
k3 = k2;
k3 = k4;
k4 = k1;
k4 = k2;
k4 = k3;
}
// Repro from #17166
function f3<T, K extends Extract<keyof T, string>, U extends T, J extends K>(
t: T, k: K, tk: T[K], u: U, j: J, uk: U[K], tj: T[J], uj: U[J]): void {
for (let key in t) {
key = k // ok, K ==> keyof T
k = key // error, keyof T =/=> K
t[key] = tk; // ok, T[K] ==> T[keyof T]
tk = t[key]; // error, T[keyof T] =/=> T[K]
}
tk = uk;
uk = tk; // error
tj = uj;
uj = tj; // error
tk = tj;
tj = tk; // error
tk = uj;
uj = tk; // error
}
// The constraint of 'keyof T' is 'keyof T'
function f4<T extends { [K in keyof T]: string }>(k: keyof T) {
k = 42; // error
k = "hello"; // error
}
// Repro from #27470
type UndefinedKeys<T extends Record<string, any>> = {
[K in keyof T]: undefined extends T[K] ? K : never
};
type MyType = {a: string, b: string | undefined}
type Result1 = UndefinedKeys<MyType>;
const a1: Result1['a'] = 'a'; // Error
const b1: Result1['b'] = 'b';
function test1<T extends Record<string, any>, K extends keyof T>(t: T, k: K) {
t[k] = 42; // Error
t[k] = "hello"; // Error
t[k] = [10, 20]; // Error
}
// Repro from #28839
function f30<T, K extends keyof T>() {
let x: Partial<Record<keyof T, string>>[K] = "hello";
}
function f31<T, K extends keyof T>() {
let x: Partial<Partial<Partial<Partial<Partial<Partial<Partial<Record<keyof T, string>>>>>>>>[K] = "hello";
}
// Repro from #51069
class Test<T extends Record<string, number>> {
testy: T;
constructor(t: T) {
this.testy = t;
}
public t(key: keyof T): number {
this.testy[key] += 1; // Error
return this.testy[key];
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/keyofInferenceIntersectsResults.ts | TypeScript | interface X {
a: string;
b: string;
}
declare function foo<T = X>(x: keyof T, y: keyof T): T;
declare function bar<T>(x: keyof T, y: keyof T): T;
const a = foo<X>('a', 'b'); // compiles cleanly
const b = foo('a', 'b'); // also clean
const c = bar('a', 'b'); // still clean | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/keyofInferenceLowerPriorityThanReturn.ts | TypeScript | // #22736
declare class Write {
protected dummy: Write;
}
declare class Col<s, a> {
protected dummy: [Col<s, a>, s, a];
}
declare class Table<Req, Def> {
protected dummy: [Table<Req, Def>, Req, Def];
}
type MakeTable<T1 extends object, T2 extends object> = {
[P in keyof T1]: Col<Write, T1[P]>;
} & {
[P in keyof T2]: Col<Write, T2[P]>;
};
declare class ConflictTarget<Cols> {
public static tableColumns<Cols>(cols: (keyof Cols)[]): ConflictTarget<Cols>;
protected dummy: [ConflictTarget<Cols>, Cols];
}
const bookTable: Table<BookReq, BookDef> = null as any
interface BookReq {
readonly title: string;
readonly serial: number;
}
interface BookDef {
readonly author: string;
readonly numPages: number | null;
}
function insertOnConflictDoNothing<Req extends object, Def extends object>(_table: Table<Req, Def>, _conflictTarget: ConflictTarget<Req & Def>): boolean {
throw new Error();
}
function f() {
insertOnConflictDoNothing(bookTable, ConflictTarget.tableColumns(["serial"])); // <-- No error here; should use the type inferred for the return type of `tableColumns`
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/keyofIntersection.ts | TypeScript | // @strict: true
// @declaration: true
type A = { a: string };
type B = { b: string };
type T01 = keyof (A & B); // "a" | "b"
type T02<T> = keyof (T & B); // "b" | keyof T
type T03<U> = keyof (A & U); // "a" | keyof U
type T04<T, U> = keyof (T & U); // keyof T | keyof U
type T05 = T02<A>; // "a" | "b"
type T06 = T03<B>; // "a" | "b"
type T07 = T04<A, B>; // "a" | "b"
// Repros from #22291
type Example1<T extends string, U extends string> = keyof (Record<T, any> & Record<U, any>);
type Result1 = Example1<'x', 'y'>; // "x" | "y"
type Result2 = keyof (Record<'x', any> & Record<'y', any>); // "x" | "y"
type Example3<T extends string> = keyof (Record<T, any>);
type Result3 = Example3<'x' | 'y'>; // "x" | "y"
type Example4<T extends string, U extends string> = (Record<T, any> & Record<U, any>);
type Result4 = keyof Example4<'x', 'y'>; // "x" | "y"
type Example5<T, U> = keyof (T & U);
type Result5 = Example5<Record<'x', any>, Record<'y', any>>; // "x" | "y"
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/lateBoundAssignmentDeclarationSupport1.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strict: true
// @target: es6
// @filename: lateBoundAssignmentDeclarationSupport1.js
// currently unsupported
const _sym = Symbol();
const _str = "my-fake-sym";
exports[_sym] = "ok";
exports[_str] = "ok";
exports.S = _sym;
// @filename: usage.js
const x = require("./lateBoundAssignmentDeclarationSupport1.js");
const y = x["my-fake-sym"];
const z = x[x.S];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/lateBoundAssignmentDeclarationSupport2.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strict: true
// @target: es6
// @filename: lateBoundAssignmentDeclarationSupport2.js
// currently unsupported
const _sym = Symbol();
const _str = "my-fake-sym";
module.exports[_sym] = "ok";
module.exports[_str] = "ok";
module.exports.S = _sym;
// @filename: usage.js
const x = require("./lateBoundAssignmentDeclarationSupport2.js");
const y = x["my-fake-sym"];
const z = x[x.S];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/lateBoundAssignmentDeclarationSupport3.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strict: true
// @target: es6
// @filename: lateBoundAssignmentDeclarationSupport3.js
// currently unsupported
const _sym = Symbol();
const _str = "my-fake-sym";
Object.defineProperty(module.exports, _sym, { value: "ok" });
Object.defineProperty(module.exports, _str, { value: "ok" });
module.exports.S = _sym;
// @filename: usage.js
const x = require("./lateBoundAssignmentDeclarationSupport3.js");
const y = x["my-fake-sym"];
const z = x[x.S];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/lateBoundAssignmentDeclarationSupport4.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strict: true
// @target: es6
// @filename: lateBoundAssignmentDeclarationSupport4.js
// currently unsupported
const _sym = Symbol();
const _str = "my-fake-sym";
function F() {
}
F.prototype[_sym] = "ok";
F.prototype[_str] = "ok";
const inst = new F();
const _y = inst[_str];
const _z = inst[_sym];
module.exports.F = F;
module.exports.S = _sym;
// @filename: usage.js
const x = require("./lateBoundAssignmentDeclarationSupport4.js");
const inst = new x.F();
const y = inst["my-fake-sym"];
const z = inst[x.S];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/lateBoundAssignmentDeclarationSupport5.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strict: true
// @target: es6
// @filename: lateBoundAssignmentDeclarationSupport5.js
// currently unsupported
const _sym = Symbol();
const _str = "my-fake-sym";
function F() {
}
F.prototype = {
[_sym]: "ok",
[_str]: "ok"
}
const inst = new F();
const _y = inst[_str];
const _z = inst[_sym];
module.exports.F = F;
module.exports.S = _sym;
// @filename: usage.js
const x = require("./lateBoundAssignmentDeclarationSupport5.js");
const inst = new x.F();
const y = inst["my-fake-sym"];
const z = inst[x.S];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/lateBoundAssignmentDeclarationSupport6.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strict: true
// @target: es6
// @filename: lateBoundAssignmentDeclarationSupport6.js
// currently unsupported
const _sym = Symbol();
const _str = "my-fake-sym";
function F() {
}
F.prototype.defsAClass = true;
Object.defineProperty(F.prototype, _str, {value: "ok"});
Object.defineProperty(F.prototype, _sym, {value: "ok"});
const inst = new F();
const _y = inst[_str];
const _z = inst[_sym];
module.exports.F = F;
module.exports.S = _sym;
// @filename: usage.js
const x = require("./lateBoundAssignmentDeclarationSupport6.js");
const inst = new x.F();
const y = inst["my-fake-sym"];
const z = inst[x.S];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/lateBoundAssignmentDeclarationSupport7.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strict: true
// @target: es6
// @filename: lateBoundAssignmentDeclarationSupport7.js
const _sym = Symbol();
const _str = "my-fake-sym";
function F() {
}
F[_sym] = "ok";
F[_str] = "ok";
module.exports.F = F;
module.exports.S = _sym;
// @filename: usage.js
const x = require("./lateBoundAssignmentDeclarationSupport7.js");
const y = x.F["my-fake-sym"];
const z = x.F[x.S];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/lateBoundClassMemberAssignmentJS.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @emitDeclarationOnly: true
// @strict: true
// @target: es6
// @declaration: true
// @filename: lateBoundClassMemberAssignmentJS.js
const _sym = Symbol("_sym");
export class MyClass {
constructor() {
this[_sym] = "ok";
}
method() {
this[_sym] = "yep";
const x = this[_sym];
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/lateBoundClassMemberAssignmentJS2.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @emitDeclarationOnly: true
// @strict: true
// @target: es6
// @declaration: true
// @filename: lateBoundClassMemberAssignmentJS2.js
const _sym = "my-fake-sym";
export class MyClass {
constructor() {
this[_sym] = "ok";
}
method() {
this[_sym] = "yep";
const x = this[_sym];
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/lateBoundClassMemberAssignmentJS3.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @emitDeclarationOnly: true
// @strict: true
// @target: es6
// @declaration: true
// @filename: lateBoundClassMemberAssignmentJS.js
const _sym = Symbol("_sym");
export class MyClass {
constructor() {
var self = this
self[_sym] = "ok";
}
method() {
var self = this
self[_sym] = "yep";
const x = self[_sym];
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/leaveOptionalParameterAsWritten.ts | TypeScript | // @module: esnext
// @outDir: dist
// @declaration: true
// @emitDeclarationOnly: true
// @strictNullChecks: true
// @Filename: a.ts
export interface Foo {}
// @Filename: b.ts
import * as a from "./a";
declare global {
namespace teams {
export namespace calling {
export import Foo = a.Foo;
}
}
}
// @Filename: c.ts
type Foo = teams.calling.Foo;
export const bar = (p?: Foo) => {} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/letIdentifierInElementAccess01.ts | TypeScript | var let: any = {};
(let[0] = 100); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/libReferenceDeclarationEmit.ts | TypeScript | // @target: esnext
// @module: commonjs
// @lib: esnext
// @declaration: true
// @filename: file1.ts
/// <reference lib="dom" preserve="true" />
export declare const elem: HTMLElement;
// @filename: file2.ts
/// <reference lib="dom" preserve="true" />
export {}
declare const elem: HTMLElement; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.