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/jsDeclarationsConstsAsNamespacesWithReferences.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: ./out // @target: es6 // @declaration: true // @filename: index.js export const colors = { royalBlue: "#6400e4", }; export const brandColors = { purple: colors.royalBlue, };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsCrossfileMerge.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @lib: es6 // @outDir: ./out // @declaration: true // @filename: index.js const m = require("./exporter"); module.exports = m.default; module.exports.memberName = "thing"; // @filename: exporter.js function validate() {} export default validate;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsDefault.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index1.js export default 12; // @filename: index2.js export default function foo() { return foo; } export const x = foo; export { foo as bar }; // @filename: index3.js export default class Foo { a = /** @type {Foo} */(null); }; export const X = Foo; export { Foo as Bar }; // @filename: index4.js import Fab from "./index3"; class Bar extends Fab { x = /** @type {Bar} */(null); } export default Bar; // @filename: index5.js // merge type alias and const (OK) export default 12; /** * @typedef {string | number} default */ // @filename: index6.js // merge type alias and function (OK) export default function func() {}; /** * @typedef {string | number} default */
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsDefaultsErr.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index1.js // merge type alias and alias (should error, see #32367) class Cls { x = 12; static y = "ok" } export default Cls; /** * @typedef {string | number} default */ // @filename: index2.js // merge type alias and class (error message improvement needed, see #32368) export default class C {}; /** * @typedef {string | number} default */ // @filename: index3.js // merge type alias and variable (behavior is borked, see #32366) const x = 12; export {x as default}; /** * @typedef {string | number} default */
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsDocCommentsOnConsts.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index1.js /** * const doc comment */ const x = (a) => { return ''; }; /** * function doc comment */ function b() { return 0; } module.exports = {x, b}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsEnumTag.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index.js /** @enum {string} */ export const Target = { START: "start", MIDDLE: "middle", END: "end", /** @type {number} */ OK_I_GUESS: 2 } /** @enum number */ export const Second = { OK: 1, /** @type {number} */ FINE: 2, } /** @enum {function(number): number} */ export const Fs = { ADD1: n => n + 1, ID: n => n, SUB1: n => n - 1 } /** * @param {Target} t * @param {Second} s * @param {Fs} f */ export function consume(t,s,f) { /** @type {string} */ var str = t /** @type {number} */ var num = s /** @type {(n: number) => number} */ var fun = f /** @type {Target} */ var v = Target.START v = 'something else' // allowed, like Typescript's classic enums and unlike its string enums } /** @param {string} s */ export function ff(s) { // element access with arbitrary string is an error only with noImplicitAny if (!Target[s]) { return null } else { return Target[s] } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsEnums.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index.js // Pretty much all of this should be an error, (since enums are forbidden in js), // but we should be able to synthesize declarations from the symbols regardless export enum A {} export enum B { Member } enum C {} export { C }; enum DD {} export { DD as D }; export enum E {} export { E as EE }; export { F as FF }; export enum F {} export enum G { A = 1, B, C } export enum H { A = "a", B = "b" } export enum I { A = "a", B = 0, C } export const enum J { A = 1, B, C } export enum K { None = 0, A = 1 << 0, B = 1 << 1, C = 1 << 2, Mask = A | B | C, } export const enum L { None = 0, A = 1 << 0, B = 1 << 1, C = 1 << 2, Mask = A | B | C, }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportAssignedClassExpression.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index.js module.exports = class Thing { /** * @param {number} p */ constructor(p) { this.t = 12 + p; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportAssignedClassExpressionAnonymous.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index.js module.exports = class { /** * @param {number} p */ constructor(p) { this.t = 12 + p; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index.js module.exports = class { /** * @param {number} p */ constructor(p) { this.t = 12 + p; } } module.exports.Sub = class { constructor() { this.instance = new module.exports(10); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportAssignedClassExpressionShadowing.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index.js class A { member = new Q(); } class Q { x = 42; } module.exports = class Q { constructor() { this.x = new A(); } } module.exports.Another = Q;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportAssignedClassInstance1.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index.js class Foo {} module.exports = new Foo();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportAssignedClassInstance2.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index.js class Foo { static stat = 10; member = 10; } module.exports = new Foo();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportAssignedClassInstance3.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index.js class Foo { static stat = 10; member = 10; } module.exports = new Foo(); module.exports.additional = 20;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportAssignedConstructorFunction.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: jsDeclarationsExportAssignedConstructorFunction.js /** @constructor */ module.exports.MyClass = function() { this.x = 1 } module.exports.MyClass.prototype = { a: function() { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportAssignedConstructorFunctionWithSub.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: jsDeclarationsExportAssignedConstructorFunctionWithSub.js /** * @param {number} p */ module.exports = function (p) { this.t = 12 + p; } module.exports.Sub = function() { this.instance = new module.exports(10); } module.exports.Sub.prototype = { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportAssignedVisibility.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: obj.js module.exports = class Obj { constructor() { this.x = 12; } } // @filename: index.js const Obj = require("./obj"); class Container { constructor() { this.usage = new Obj(); } } module.exports = Container;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportAssignmentExpressionPlusSecondary.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index.js const Strings = { a: "A", b: "B" }; module.exports = { thing: "ok", also: "ok", desc: { item: "ok" } }; module.exports.Strings = Strings;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportAssignmentWithKeywordName.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index.js var x = 12; module.exports = { extends: 'base', more: { others: ['strs'] }, x };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportDefinePropertyEmit.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: ./out // @declaration: true // @filename: index.js Object.defineProperty(module.exports, "a", { value: function a() {} }); Object.defineProperty(module.exports, "b", { value: function b() {} }); Object.defineProperty(module.exports.b, "cat", { value: "cat" }); /** * @param {number} a * @param {number} b * @return {string} */ function d(a, b) { return /** @type {*} */(null); } Object.defineProperty(module.exports, "d", { value: d }); /** * @template T,U * @param {T} a * @param {U} b * @return {T & U} */ function e(a, b) { return /** @type {*} */(null); } Object.defineProperty(module.exports, "e", { value: e }); /** * @template T * @param {T} a */ function f(a) { return a; } Object.defineProperty(module.exports, "f", { value: f }); Object.defineProperty(module.exports.f, "self", { value: module.exports.f }); /** * @param {{x: string}} a * @param {{y: typeof module.exports.b}} b */ function g(a, b) { return a.x && b.y(); } Object.defineProperty(module.exports, "g", { value: g }); /** * @param {{x: string}} a * @param {{y: typeof module.exports.b}} b */ function hh(a, b) { return a.x && b.y(); } Object.defineProperty(module.exports, "h", { value: hh }); Object.defineProperty(module.exports, "i", { value: function i(){} }); Object.defineProperty(module.exports, "ii", { value: module.exports.i }); // note that this last one doesn't make much sense in cjs, since exports aren't hoisted bindings Object.defineProperty(module.exports, "jj", { value: module.exports.j }); Object.defineProperty(module.exports, "j", { value: function j() {} });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportDoubleAssignmentInClosure.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: ./out // @declaration: true // @filename: index.js // @ts-nocheck function foo() { module.exports = exports = function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); }; const m = function () { // I have no idea what to put here } exports.methods = m; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportForms.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: cls.js export class Foo {} // @filename: func.js export function func() {} // @filename: bar.js export * from "./cls"; // @filename: bar2.js export * from "./func"; export * from "./cls"; // @filename: baz.js import {Foo} from "./cls"; export {Foo}; // @filename: bat.js import * as ns from "./cls"; export default ns; // @filename: ban.js import * as ns from "./cls"; export {ns}; // @filename: bol.js import * as ns from "./cls"; export { ns as classContainer }; // @filename: cjs.js const ns = require("./cls"); module.exports = { ns }; // @filename: cjs2.js const ns = require("./cls"); module.exports = ns; // @filename: cjs3.js const ns = require("./cls"); module.exports.ns = ns; // @filename: cjs4.js const ns = require("./cls"); module.exports.names = ns; // @filename: includeAll.js import "./cjs4"; import "./cjs3"; import "./cjs2"; import "./cjs"; import "./bol"; import "./ban"; import "./bat"; import "./baz"; import "./bar"; import "./bar2";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportSpecifierNonlocal.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: source.js export class Thing {} export class OtherThing {} // @filename: index.js export { Thing, OtherThing as default } from "./source";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportSubAssignments.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: cls.js const Strings = { a: "A", b: "B" }; class Foo {} module.exports = Foo; module.exports.Strings = Strings;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsExportedClassAliases.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: ./out // @declaration: true // @filename: utils/errors.js class FancyError extends Error { constructor(status) { super(`error with status ${status}`); } } module.exports = { FancyError }; // @filename: utils/index.js // issue arises here on compilation const errors = require("./errors"); module.exports = { errors };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsFunctionClassesCjsExportAssignment.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: timer.js /** * @param {number} timeout */ function Timer(timeout) { this.timeout = timeout; } module.exports = Timer; // @filename: hook.js /** * @typedef {(arg: import("./context")) => void} HookHandler */ /** * @param {HookHandler} handle */ function Hook(handle) { this.handle = handle; } module.exports = Hook; // @filename: context.js /** * Imports * * @typedef {import("./timer")} Timer * @typedef {import("./hook")} Hook * @typedef {import("./hook").HookHandler} HookHandler */ /** * Input type definition * * @typedef {Object} Input * @prop {Timer} timer * @prop {Hook} hook */ /** * State type definition * * @typedef {Object} State * @prop {Timer} timer * @prop {Hook} hook */ /** * New `Context` * * @class * @param {Input} input */ function Context(input) { if (!(this instanceof Context)) { return new Context(input) } this.state = this.construct(input); } Context.prototype = { /** * @param {Input} input * @param {HookHandler=} handle * @returns {State} */ construct(input, handle = () => void 0) { return input; } } module.exports = Context;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsFunctionJSDoc.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: source.js /** * Foos a bar together using an `a` and a `b` * @param {number} a * @param {string} b */ export function foo(a, b) {} /** * Legacy - DO NOT USE */ export class Aleph { /** * Impossible to construct. * @param {Aleph} a * @param {null} b */ constructor(a, b) { /** * Field is always null */ this.field = b; } /** * Doesn't actually do anything * @returns {void} */ doIt() {} } /** * Not the speed of light */ export const c = 12;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsFunctionKeywordProp.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: source.js function foo() {} foo.null = true; function bar() {} bar.async = true; bar.normal = false; function baz() {} baz.class = true; baz.normal = false;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsFunctionKeywordPropExhaustive.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: source.js function foo() {} // properties foo.x = 1; foo.y = 1; // keywords foo.break = 1; foo.case = 1; foo.catch = 1; foo.class = 1; foo.const = 1; foo.continue = 1; foo.debugger = 1; foo.default = 1; foo.delete = 1; foo.do = 1; foo.else = 1; foo.enum = 1; foo.export = 1; foo.extends = 1; foo.false = 1; foo.finally = 1; foo.for = 1; foo.function = 1; foo.if = 1; foo.import = 1; foo.in = 1; foo.instanceof = 1; foo.new = 1; foo.null = 1; foo.return = 1; foo.super = 1; foo.switch = 1; foo.this = 1; foo.throw = 1; foo.true = 1; foo.try = 1; foo.typeof = 1; foo.var = 1; foo.void = 1; foo.while = 1; foo.with = 1; foo.implements = 1; foo.interface = 1; foo.let = 1; foo.package = 1; foo.private = 1; foo.protected = 1; foo.public = 1; foo.static = 1; foo.yield = 1; foo.abstract = 1; foo.as = 1; foo.asserts = 1; foo.any = 1; foo.async = 1; foo.await = 1; foo.boolean = 1; foo.constructor = 1; foo.declare = 1; foo.get = 1; foo.infer = 1; foo.is = 1; foo.keyof = 1; foo.module = 1; foo.namespace = 1; foo.never = 1; foo.readonly = 1; foo.require = 1; foo.number = 1; foo.object = 1; foo.set = 1; foo.string = 1; foo.symbol = 1; foo.type = 1; foo.undefined = 1; foo.unique = 1; foo.unknown = 1; foo.from = 1; foo.global = 1; foo.bigint = 1; foo.of = 1;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsFunctionLikeClasses.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: source.js /** * @param {number} x * @param {number} y */ export function Point(x, y) { if (!(this instanceof Point)) { return new Point(x, y); } this.x = x; this.y = y; } // @filename: referencer.js import {Point} from "./source"; /** * @param {Point} p */ export function magnitude(p) { return Math.sqrt(p.x ** 2 + p.y ** 2); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsFunctionLikeClasses2.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: source.js /** * @param {number} len */ export function Vec(len) { /** * @type {number[]} */ this.storage = new Array(len); } Vec.prototype = { /** * @param {Vec} other */ dot(other) { if (other.storage.length !== this.storage.length) { throw new Error(`Dot product only applicable for vectors of equal length`); } let sum = 0; for (let i = 0; i < this.storage.length; i++) { sum += (this.storage[i] * other.storage[i]); } return sum; }, magnitude() { let sum = 0; for (let i = 0; i < this.storage.length; i++) { sum += (this.storage[i] ** 2); } return Math.sqrt(sum); } } /** * @param {number} x * @param {number} y */ export function Point2D(x, y) { if (!(this instanceof Point2D)) { return new Point2D(x, y); } Vec.call(this, 2); this.x = x; this.y = y; } Point2D.prototype = { __proto__: Vec, get x() { return this.storage[0]; }, /** * @param {number} x */ set x(x) { this.storage[0] = x; }, get y() { return this.storage[1]; }, /** * @param {number} y */ set y(y) { this.storage[1] = y; } }; // @filename: referencer.js import {Point2D} from "./source"; export const origin = new Point2D(0, 0); // export const res = Point2D(2, 3).dot(origin); // TODO: when __proto__ works, validate this
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsFunctionPrototypeStatic.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: source.js module.exports = MyClass; function MyClass() {} MyClass.staticMethod = function() {} MyClass.prototype.method = function() {} MyClass.staticProperty = 123; /** * Callback to be invoked when test execution is complete. * * @callback DoneCB * @param {number} failures - Number of failures that occurred. */
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsFunctionWithDefaultAssignedMember.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: ./out // @declaration: true // @filename: index.js function foo() {} foo.foo = foo; foo.default = foo; module.exports = foo;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsFunctions.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: ./out // @declaration: true // @filename: index.js export function a() {} export function b() {} b.cat = "cat"; export function c() {} c.Cls = class {} /** * @param {number} a * @param {number} b * @return {string} */ export function d(a, b) { return /** @type {*} */(null); } /** * @template T,U * @param {T} a * @param {U} b * @return {T & U} */ export function e(a, b) { return /** @type {*} */(null); } /** * @template T * @param {T} a */ export function f(a) { return a; } f.self = f; /** * @param {{x: string}} a * @param {{y: typeof b}} b */ function g(a, b) { return a.x && b.y(); } export { g }; /** * @param {{x: string}} a * @param {{y: typeof b}} b */ function hh(a, b) { return a.x && b.y(); } export { hh as h }; export function i() {} export { i as ii }; export { j as jj }; export function j() {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsFunctionsCjs.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: ./out // @declaration: true // @filename: index.js module.exports.a = function a() {} module.exports.b = function b() {} module.exports.b.cat = "cat"; module.exports.c = function c() {} module.exports.c.Cls = class {} /** * @param {number} a * @param {number} b * @return {string} */ module.exports.d = function d(a, b) { return /** @type {*} */(null); } /** * @template T,U * @param {T} a * @param {U} b * @return {T & U} */ module.exports.e = function e(a, b) { return /** @type {*} */(null); } /** * @template T * @param {T} a */ module.exports.f = function f(a) { return a; } module.exports.f.self = module.exports.f; /** * @param {{x: string}} a * @param {{y: typeof module.exports.b}} b */ function g(a, b) { return a.x && b.y(); } module.exports.g = g; /** * @param {{x: string}} a * @param {{y: typeof module.exports.b}} b */ function hh(a, b) { return a.x && b.y(); } module.exports.h = hh; module.exports.i = function i() {} module.exports.ii = module.exports.i; // note that this last one doesn't make much sense in cjs, since exports aren't hoisted bindings module.exports.jj = module.exports.j; module.exports.j = function j() {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsGetterSetter.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: ./out // @target: es6 // @declaration: true // @filename: index.js export class A { get x() { return 12; } } export class B { /** * @param {number} _arg */ set x(_arg) { } } export class C { get x() { return 12; } set x(_arg) { } } export class D {} Object.defineProperty(D.prototype, "x", { get() { return 12; } }); export class E {} Object.defineProperty(E.prototype, "x", { /** * @param {number} _arg */ set(_arg) {} }); export class F {} Object.defineProperty(F.prototype, "x", { get() { return 12; }, /** * @param {number} _arg */ set(_arg) {} }); export class G {} Object.defineProperty(G.prototype, "x", { /** * @param {number[]} args */ set(...args) {} }); export class H {} Object.defineProperty(H.prototype, "x", { set() {} }); export class I {} Object.defineProperty(I.prototype, "x", { /** * @param {number} v */ set: (v) => {} }); /** * @param {number} v */ const jSetter = (v) => {} export class J {} Object.defineProperty(J.prototype, "x", { set: jSetter }); /** * @param {number} v */ const kSetter1 = (v) => {} /** * @param {number} v */ const kSetter2 = (v) => {} export class K {} Object.defineProperty(K.prototype, "x", { set: Math.random() ? kSetter1 : kSetter2 }); /** * @param {number} v */ const lSetter1 = (v) => {} /** * @param {string} v */ const lSetter2 = (v) => {} export class L {} Object.defineProperty(L.prototype, "x", { set: Math.random() ? lSetter1 : lSetter2 }); /** * @param {number | boolean} v */ const mSetter1 = (v) => {} /** * @param {string | boolean} v */ const mSetter2 = (v) => {} export class M {} Object.defineProperty(M.prototype, "x", { set: Math.random() ? mSetter1 : mSetter2 });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsImportAliasExposedWithinNamespace.ts
TypeScript
// @declaration: true // @emitDeclarationOnly: true // @allowJs: true // @checkJs: true // @module: commonjs // @target: es6 // @filename: file.js /** * @namespace myTypes * @global * @type {Object<string,*>} */ const myTypes = { // SOME PROPS HERE }; /** @typedef {string|RegExp|Array<string|RegExp>} myTypes.typeA */ /** * @typedef myTypes.typeB * @property {myTypes.typeA} prop1 - Prop 1. * @property {string} prop2 - Prop 2. */ /** @typedef {myTypes.typeB|Function} myTypes.typeC */ export {myTypes}; // @filename: file2.js import {myTypes} from './file.js'; /** * @namespace testFnTypes * @global * @type {Object<string,*>} */ const testFnTypes = { // SOME PROPS HERE }; /** @typedef {boolean|myTypes.typeC} testFnTypes.input */ /** * @function testFn * @description A test function. * @param {testFnTypes.input} input - Input. * @returns {number|null} Result. */ function testFn(input) { if (typeof input === 'number') { return 2 * input; } else { return null; } } export {testFn, testFnTypes};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsImportAliasExposedWithinNamespaceCjs.ts
TypeScript
// @declaration: true // @emitDeclarationOnly: true // @allowJs: true // @checkJs: true // @module: commonjs // @target: es6 // @filename: file.js /** * @namespace myTypes * @global * @type {Object<string,*>} */ const myTypes = { // SOME PROPS HERE }; /** @typedef {string|RegExp|Array<string|RegExp>} myTypes.typeA */ /** * @typedef myTypes.typeB * @property {myTypes.typeA} prop1 - Prop 1. * @property {string} prop2 - Prop 2. */ /** @typedef {myTypes.typeB|Function} myTypes.typeC */ exports.myTypes = myTypes; // @filename: file2.js const {myTypes} = require('./file.js'); /** * @namespace testFnTypes * @global * @type {Object<string,*>} */ const testFnTypes = { // SOME PROPS HERE }; /** @typedef {boolean|myTypes.typeC} testFnTypes.input */ /** * @function testFn * @description A test function. * @param {testFnTypes.input} input - Input. * @returns {number|null} Result. */ function testFn(input) { if (typeof input === 'number') { return 2 * input; } else { return null; } } module.exports = {testFn, testFnTypes};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsImportNamespacedType.ts
TypeScript
// @declaration: true // @emitDeclarationOnly: true // @checkJs: true // @filename: file.js import { dummy } from './mod1' /** @type {import('./mod1').Dotted.Name} - should work */ var dot2 // @filename: mod1.js /** @typedef {number} Dotted.Name */ export var dummy = 1
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsImportTypeBundled.ts
TypeScript
// @allowJs: true // @checkJs: true // @outFile: out.js // @module: amd // @declaration: true // @filename: folder/mod1.js /** * @typedef {{x: number}} Item */ /** * @type {Item}; */ const x = {x: 12}; module.exports = x; // @filename: index.js /** @type {(typeof import("./folder/mod1"))[]} */ const items = [{x: 12}]; module.exports = items;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsInterfaces.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index.js // Pretty much all of this should be an error, (since interfaces are forbidden in js), // but we should be able to synthesize declarations from the symbols regardless export interface A {} export interface B { cat: string; } export interface C<T, U> { field: T & U; optionalField?: T; readonly readonlyField: T & U; readonly readonlyOptionalField?: U; (): number; (x: T): U; <Q>(x: Q): T & Q; new (): string; new (x: T): U; new <Q>(x: Q): T & Q; method<Q = number>(): number; method<Q>(a: T & Q): Q & number; method(a?: number): number; method(...args: any[]): number; optMethod?(): number; } interface G {} export { G }; interface HH {} export { HH as H }; export interface I {} export { I as II }; export { J as JJ }; export interface J {} export interface K extends I,J { x: string; } export interface L extends K { y: string; } export interface M<T> { field: T; } export interface N<U> extends M<U> { other: U; } export interface O { [idx: string]: string; } export interface P extends O {} export interface Q extends O { [idx: string]: "ok"; } export interface R extends O { [idx: number]: "ok"; } export interface S extends O { [idx: string]: "ok"; [idx: number]: never; } export interface T { [idx: number]: string; } export interface U extends T {} export interface V extends T { [idx: string]: string; } export interface W extends T { [idx: number]: "ok"; } export interface X extends T { [idx: string]: string; [idx: number]: "ok"; } export interface Y { [idx: string]: {x: number}; [idx: number]: {x: number, y: number}; } export interface Z extends Y {} export interface AA extends Y { [idx: string]: {x: number, y: number}; } export interface BB extends Y { [idx: number]: {x: 0, y: 0}; } export interface CC extends Y { [idx: string]: {x: number, y: number}; [idx: number]: {x: 0, y: 0}; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsJSDocRedirectedLookups.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es6 // @outDir: ./out // @declaration: true // @strict: true // @noImplicitAny: false // @filename: index.js // these are recognized as TS concepts by the checker /** @type {String} */const a = ""; /** @type {Number} */const b = 0; /** @type {Boolean} */const c = true; /** @type {Void} */const d = undefined; /** @type {Undefined} */const e = undefined; /** @type {Null} */const f = null; /** @type {Function} */const g = () => void 0; /** @type {function} */const h = () => void 0; /** @type {array} */const i = []; /** @type {promise} */const j = Promise.resolve(0); /** @type {Object<string, string>} */const k = {x: "x"}; // these are not recognized as anything and should just be lookup failures // ignore the errors to try to ensure they're emitted as `any` in declaration emit // @ts-ignore /** @type {class} */const l = true; // @ts-ignore /** @type {bool} */const m = true; // @ts-ignore /** @type {int} */const n = true; // @ts-ignore /** @type {float} */const o = true; // @ts-ignore /** @type {integer} */const p = true; // or, in the case of `event` likely erroneously refers to the type of the global Event object /** @type {event} */const q = undefined;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsMissingGenerics.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: file.js /** * @param {Array} x */ function x(x) {} /** * @param {Promise} x */ function y(x) {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsMissingTypeParameters.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: file.js /** * @param {Array=} y desc */ function x(y) { } // @ts-ignore /** @param {function (Array)} func Invoked */ function y(func) { return; } /** * @return {(Array.<> | null)} list of devices */ function z() { return null ;} /** * * @return {?Promise} A promise */ function w() { return null; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsModuleReferenceHasEmit.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: index.js /** * @module A */ class A {} /** * Target element * @type {module:A} */ export let el = null; export default A;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsMultipleExportFromMerge.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: items.js export const a = 1; export const b = 2; export const c = 3; // @filename: justone.js export { a, b, c } from "./items"; // @filename: two.js export { a } from "./items"; export { b, c } from "./items"; // @filename: multiple.js export {a, b} from "./items"; export {a as aa} from "./two"; export {b as bb} from "./two"; export {c} from "./two" export {c as cc} from "./items";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsNestedParams.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es6 // @outDir: ./out // @declaration: true // @filename: file.js class X { /** * Cancels the request, sending a cancellation to the other party * @param {Object} error __auto_generated__ * @param {string?} error.reason the error reason to send the cancellation with * @param {string?} error.code the error code to send the cancellation with * @returns {Promise.<*>} resolves when the event has been sent. */ async cancel({reason, code}) {} } class Y { /** * Cancels the request, sending a cancellation to the other party * @param {Object} error __auto_generated__ * @param {string?} error.reason the error reason to send the cancellation with * @param {Object} error.suberr * @param {string?} error.suberr.reason the error reason to send the cancellation with * @param {string?} error.suberr.code the error code to send the cancellation with * @returns {Promise.<*>} resolves when the event has been sent. */ async cancel({reason, suberr}) {} }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsOptionalTypeLiteralProps1.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: esnext // @outDir: ./out // @declaration: true // @filename: foo.js /** * foo * * @public * @param {object} opts * @param {number} opts.a * @param {number} [opts.b] * @param {number} [opts.c] * @returns {number} */ function foo({ a, b, c }) { return a + b + c; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsOptionalTypeLiteralProps2.ts
TypeScript
// @allowJs: true // @checkJs: true // @strict: true // @target: esnext // @outDir: ./out // @declaration: true // @filename: foo.js /** * foo * * @public * @param {object} opts * @param {number} opts.a * @param {number} [opts.b] * @param {number} [opts.c] * @returns {number} */ function foo({ a, b, c }) { return a + (b ?? 0) + (c ?? 0); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsParameterTagReusesInputNodeInEmit1.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es6 // @outDir: ./out // @declaration: true // @filename: base.js class Base { constructor() {} } const BaseFactory = () => { return new Base(); }; BaseFactory.Base = Base; module.exports = BaseFactory; // @filename: file.js /** @typedef {import('./base')} BaseFactory */ /** * @callback BaseFactoryFactory * @param {import('./base')} factory */ /** @enum {import('./base')} */ const couldntThinkOfAny = {} /** * * @param {InstanceType<BaseFactory["Base"]>} base * @returns {InstanceType<BaseFactory["Base"]>} */ const test = (base) => { return base; };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsParameterTagReusesInputNodeInEmit2.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es6 // @outDir: ./out // @declaration: true // @filename: base.js class Base { constructor() {} } const BaseFactory = () => { return new Base(); }; BaseFactory.Base = Base; module.exports = BaseFactory; // @filename: file.js /** @typedef {typeof import('./base')} BaseFactory */ /** * * @param {InstanceType<BaseFactory["Base"]>} base * @returns {InstanceType<BaseFactory["Base"]>} */ const test = (base) => { return base; };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsPrivateFields01.ts
TypeScript
// @target: esnext // @allowJS: true // @declaration: true // @emitDeclarationOnly: true // @filename: file.js export class C { #hello = "hello"; #world = 100; #calcHello() { return this.#hello; } get #screamingHello() { return this.#hello.toUpperCase(); } /** @param value {string} */ set #screamingHello(value) { throw "NO"; } getWorld() { return this.#world; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsReexportAliases.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: cls.js export default class Foo {} // @filename: usage.js import {default as Fooa} from "./cls"; export const x = new Fooa(); export {default as Foob} from "./cls";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsReexportAliasesEsModuleInterop.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @esModuleInterop: true // @filename: cls.js class Foo {} module.exports = Foo; // @filename: usage.js import {default as Fooa} from "./cls"; export const x = new Fooa(); export {default as Foob} from "./cls";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsReexportedCjsAlias.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: lib.js /** * @param {string} a */ function bar(a) { return a + a; } class SomeClass { a() { return 1; } } module.exports = { bar, SomeClass } // @filename: main.js const { SomeClass, SomeClass: Another } = require('./lib'); module.exports = { SomeClass, Another }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsReferenceToClassInstanceCrossFile.ts
TypeScript
// @allowJs: true // @checkJs: true // @moduleResolution: node // @declaration: true // @emitDeclarationOnly: true // @filename: rectangle.js class Rectangle { constructor() { console.log("I'm a rectangle!"); } } module.exports = { Rectangle }; // @filename: index.js const {Rectangle} = require('./rectangle'); class Render { constructor() { /** * Object list * @type {Rectangle[]} */ this.objects = []; } /** * Adds a rectangle * * @returns {Rectangle} the rect */ addRectangle() { const obj = new Rectangle(); this.objects.push(obj); return obj; } } module.exports = { Render }; // @filename: test.js const {Render} = require("./index"); let render = new Render(); render.addRectangle(); console.log("Objects", render.objects);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsRestArgsWithThisTypeInJSDocFunction.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: bug38550.js export class Clazz { /** * @param {function(this:Object, ...*):*} functionDeclaration */ method(functionDeclaration) {} }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsReusesExistingNodesMappingJSDocTypes.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: /out // @lib: es6 // @declaration: true // @filename: index.js /** @type {?} */ export const a = null; /** @type {*} */ export const b = null; /** @type {string?} */ export const c = null; /** @type {string=} */ export const d = null; /** @type {string!} */ export const e = null; /** @type {function(string, number): object} */ export const f = null; /** @type {function(new: object, string, number)} */ export const g = null; /** @type {Object.<string, number>} */ export const h = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsReusesExistingTypeAnnotations.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: esnext // @strict: true // @declaration: true // @filename: index.js // @outDir: /out class С1 { /** @type {string=} */ p1 = undefined; /** @type {string | undefined} */ p2 = undefined; /** @type {?string} */ p3 = null; /** @type {string | null} */ p4 = null; } class С2 { /** @type {string=} */ get p1() { return undefined; } /** @type {string | undefined} */ get p2() { return undefined; } /** @type {?string} */ get p3() { return null; } /** @type {string | null} */ get p4() { return null; } } class С3 { /** @type {string=} */ get p1() { return undefined; } /** @param {string=} value */ set p1(value) { this.p1 = value; } /** @type {string | undefined} */ get p2() { return undefined; } /** @param {string | undefined} value */ set p2(value) { this.p2 = value; } /** @type {?string} */ get p3() { return null; } /** @param {?string} value */ set p3(value) { this.p3 = value; } /** @type {string | null} */ get p4() { return null; } /** @param {string | null} value */ set p4(value) { this.p4 = value; } } class С4 { /** @param {string=} value */ set p1(value) { this.p1 = value; } /** @param {string | undefined} value */ set p2(value) { this.p2 = value; } /** @param {?string} value */ set p3(value) { this.p3 = value; } /** @param {string | null} value */ set p4(value) { this.p4 = value; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsSubclassWithExplicitNoArgumentConstructor.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: /out // @lib: es6 // @declaration: true // @filename: index.js export class Super { /** * @param {string} firstArg * @param {string} secondArg */ constructor(firstArg, secondArg) { } } export class Sub extends Super { constructor() { super('first', 'second'); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsThisTypes.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: /out // @lib: es6 // @declaration: true // @filename: index.js export class A { /** @returns {this} */ method() { return this; } } export default class Base extends A { // This method is required to reproduce #35932 verify() { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsTypeAliases.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: ./out // @declaration: true // @filename: index.js export {}; // flag file as module /** * @typedef {string | number | symbol} PropName */ /** * Callback * * @callback NumberToStringCb * @param {number} a * @returns {string} */ /** * @template T * @typedef {T & {name: string}} MixinName */ /** * Identity function * * @template T * @callback Identity * @param {T} x * @returns {T} */ // @filename: mixed.js /** * @typedef {{x: string} | number | LocalThing | ExportedThing} SomeType */ /** * @param {number} x * @returns {SomeType} */ function doTheThing(x) { return {x: ""+x}; } class ExportedThing { z = "ok" } module.exports = { doTheThing, ExportedThing, }; class LocalThing { y = "ok" }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsTypeReassignmentFromDeclaration.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: /out // @lib: es6 // @declaration: true // @filename: /some-mod.d.ts interface Item { x: string; } declare const items: Item[]; export = items; // @filename: index.js /** @type {typeof import("/some-mod")} */ const items = []; module.exports = items;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsTypeReassignmentFromDeclaration2.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: ./out // @lib: es6 // @declaration: true // @filename: some-mod.d.ts interface Item { x: string; } declare function getItems(): Item[]; export = getItems; // @filename: index.js const items = require("./some-mod")(); module.exports = items;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsTypeReferences.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: tests/cases/conformance/jsdoc/declarations/out // @declaration: true // @filename: node_modules/@types/node/index.d.ts declare module "fs" { export class Something {} } // @filename: index.js /// <reference types="node" /> const Something = require("fs").Something; const thing = new Something(); module.exports = { thing };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsTypeReferences2.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: tests/cases/conformance/jsdoc/declarations/out // @declaration: true // @filename: something.ts export const o = { a: 1, m: 1 } // @filename: index.js const{ a, m } = require("./something").o; const thing = a + m module.exports = { thing };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsTypeReferences3.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: tests/cases/conformance/jsdoc/declarations/out // @declaration: true // @filename: node_modules/@types/node/index.d.ts declare module "fs" { export class Something {} } // @filename: index.js /// <reference types="node" /> const Something = require("fs").Something; module.exports.A = {} module.exports.A.B = { thing: new Something() }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsTypeReferences4.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: es5 // @outDir: tests/cases/conformance/jsdoc/declarations/out // @declaration: true // @filename: node_modules/@types/node/index.d.ts declare module "fs" { export class Something {} } // @filename: index.js /// <reference types="node" /> export const Something = 2; // to show conflict that can occur // @ts-ignore export namespace A { // @ts-ignore export namespace B { const Something = require("fs").Something; const thing = new Something(); // @ts-ignore export { thing }; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsTypedefAndImportTypes.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: ./out // @declaration: true // @filename: conn.js /** * @typedef {string | number} Whatever */ class Conn { constructor() {} item = 3; method() {} } module.exports = Conn; // @filename: usage.js /** * @typedef {import("./conn")} Conn */ class Wrap { /** * @param {Conn} c */ constructor(c) { this.connItem = c.item; /** @type {import("./conn").Whatever} */ this.another = ""; } } module.exports = { Wrap };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsTypedefAndLatebound.ts
TypeScript
// @lib: es2017 // @allowJs: true // @checkJs: true // @noEmit: true // from #53967, based on webpack/webpack#16957 // @filename: index.js const LazySet = require("./LazySet"); /** @type {LazySet} */ const stringSet = undefined; stringSet.addAll(stringSet); // @filename: LazySet.js // Comment out this JSDoc, and note that the errors index.js go away. /** * @typedef {Object} SomeObject */ class LazySet { /** * @param {LazySet} iterable */ addAll(iterable) {} [Symbol.iterator]() {} } module.exports = LazySet;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsTypedefDescriptionsPreserved.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: ./out // @declaration: true // @filename: index.js /** * Options for Foo <------------ * @typedef {Object} FooOptions * @property {boolean} bar - Marvin K Mooney * @property {string} baz - Sylvester McMonkey McBean */ /** * Multiline * Options * for Foo <------------ * @typedef {Object} BarOptions * @property {boolean} bar - Marvin K Mooney * @property {string} baz - Sylvester McMonkey McBean */
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsTypedefFunction.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: esnext // @outDir: ./out // @declaration: true // @filename: foo.js /** * @typedef {{ * [id: string]: [Function, Function]; * }} ResolveRejectMap */ let id = 0 /** * @param {ResolveRejectMap} handlers * @returns {Promise<any>} */ const send = handlers => new Promise((resolve, reject) => { handlers[++id] = [resolve, reject] })
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsTypedefPropertyAndExportAssignment.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: ./out // @lib: es6 // @declaration: true // @filename: module.js /** @typedef {'parseHTML'|'styleLayout'} TaskGroupIds */ /** * @typedef TaskGroup * @property {TaskGroupIds} id * @property {string} label * @property {string[]} traceEventNames */ /** * @type {{[P in TaskGroupIds]: {id: P, label: string}}} */ const taskGroups = { parseHTML: { id: 'parseHTML', label: 'Parse HTML & CSS' }, styleLayout: { id: 'styleLayout', label: 'Style & Layout' }, } /** @type {Object<string, TaskGroup>} */ const taskNameToGroup = {}; module.exports = { taskGroups, taskNameToGroup, }; // @filename: index.js const {taskGroups, taskNameToGroup} = require('./module.js'); /** @typedef {import('./module.js').TaskGroup} TaskGroup */ /** * @typedef TaskNode * @prop {TaskNode[]} children * @prop {TaskNode|undefined} parent * @prop {TaskGroup} group */ /** @typedef {{timers: Map<string, TaskNode>}} PriorTaskData */ class MainThreadTasks { /** * @param {TaskGroup} x * @param {TaskNode} y */ constructor(x, y){} } module.exports = MainThreadTasks;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsDeclarationsUniqueSymbolUsage.ts
TypeScript
// @allowJs: true // @checkJs: true // @declaration: true // @emitDeclarationOnly: true // @lib: es2017 // @filename: a.js export const kSymbol = Symbol("my-symbol"); /** * @typedef {{[kSymbol]: true}} WithSymbol */ // @filename: b.js /** * @returns {import('./a').WithSymbol} * @param {import('./a').WithSymbol} value */ export function b(value) { return value; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsObjectsMarkedAsOpenEnded.ts
TypeScript
// @outFile: output.js // @allowJs: true // @filename: a.js var variable = {}; variable.a = 0; class C { initializedMember = {}; constructor() { this.member = {}; this.member.a = 0; } } var obj = { property: {} }; obj.property.a = 0; var arr = [{}]; function getObj() { return {}; } // @filename: b.ts variable.a = 1; (new C()).member.a = 1; (new C()).initializedMember.a = 1; obj.property.a = 1; arr[0].a = 1; getObj().a = 1;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocAccessibilityTags.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: esnext // @noEmit: true // @Filename: jsdocAccessibilityTag.js class A { /** * Ap docs * * @private */ priv = 4; /** * Aq docs * * @protected */ prot = 5; /** * Ar docs * * @public */ pub = 6; /** @public */ get ack() { return this.priv } /** @private */ set ack(value) { } } class C { constructor() { /** * Cp docs * * @private */ this.priv2 = 1; /** * Cq docs * * @protected */ this.prot2 = 2; /** * Cr docs * * @public */ this.pub2 = 3; } h() { return this.priv2 } } class B extends A { m() { this.priv + this.prot + this.pub } } class D extends C { n() { this.priv2 + this.prot2 + this.pub2 } } new A().priv + new A().prot + new A().pub new B().priv + new B().prot + new B().pub new C().priv2 + new C().prot2 + new C().pub2 new D().priv2 + new D().prot2 + new D().pub2
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocAccessibilityTagsDeclarations.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: esnext // @outFile: foo.js // @declaration: true // @Filename: jsdocAccessibilityTagDeclarations.js class Protected { /** @protected */ constructor(c) { /** @protected */ this.c = c } /** @protected */ m() { return this.c } /** @protected */ get p() { return this.c } /** @protected */ set p(value) { this.c = value } } class Private { /** @private */ constructor(c) { /** @private */ this.c = c } /** @private */ m() { return this.c } /** @private */ get p() { return this.c } /** @private */ set p(value) { this.c = value } } // https://github.com/microsoft/TypeScript/issues/38401 class C { constructor(/** @public */ x, /** @protected */ y, /** @private */ z) { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocAugmentsMissingType.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @Filename: /a.js class A { constructor() { this.x = 0; } } /** @augments */ class B extends A { m() { this.x } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocAugments_errorInExtendsExpression.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @Filename: /a.js class A {} /** @augments A */ class B extends err() {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocAugments_nameMismatch.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @Filename: /b.js class A {} class B {} /** @augments A */ class C extends B {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocAugments_noExtends.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @Filename: /b.js class A { constructor() { this.x = 0; } } /** @augments A */ class B { m() { return this.x; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocAugments_notAClass.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @Filename: /b.js class A {} /** @augments A */ function b() {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocAugments_qualifiedName.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @Filename: /a.js export class A {} // @Filename: /b.js import * as a from "./a"; /** @augments a.A */ class B {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocAugments_withTypeParameter.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @Filename: /a.d.ts declare class A<T> { x: T } // @Filename: /b.js /** @augments A<number> */ class B extends A { m() { return this.x; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocBindingInUnreachableCode.ts
TypeScript
// @allowJs: true // @noEmit: true // @checkJs: true // @Filename: bug27341.js if (false) { /** * @param {string} s */ const x = function (s) { }; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocCatchClauseWithTypeAnnotation.ts
TypeScript
// @allowJs: true // @checkJs: true // @target: esnext // @noImplicitAny: true // @outDir: out // @Filename: foo.js /** * @typedef {any} Any */ /** * @typedef {unknown} Unknown */ function fn() { try { } catch (x) { } // should be OK try { } catch (/** @type {any} */ err) { } // should be OK try { } catch (/** @type {Any} */ err) { } // should be OK try { } catch (/** @type {unknown} */ err) { } // should be OK try { } catch (/** @type {Unknown} */ err) { } // should be OK try { } catch (err) { err.foo; } // should be OK try { } catch (/** @type {any} */ err) { err.foo; } // should be OK try { } catch (/** @type {Any} */ err) { err.foo; } // should be OK try { } catch (/** @type {unknown} */ err) { console.log(err); } // should be OK try { } catch (/** @type {Unknown} */ err) { console.log(err); } // should be OK try { } catch (/** @type {unknown} */ err) { err.foo; } // error in the body try { } catch (/** @type {Unknown} */ err) { err.foo; } // error in the body try { } catch (/** @type {Error} */ err) { } // error in the type try { } catch (/** @type {object} */ err) { } // error in the type try { console.log(); } // @ts-ignore catch (/** @type {number} */ err) { // e should not be a `number` console.log(err.toLowerCase()); } // minor bug: shows that the `catch` argument is skipped when checking scope try { } catch (err) { /** @type {string} */ let err; } try { } catch (err) { /** @type {boolean} */ var err; } try { } catch ({ x }) { } // should be OK try { } catch (/** @type {any} */ { x }) { x.foo; } // should be OK try { } catch (/** @type {Any} */ { x }) { x.foo;} // should be OK try { } catch (/** @type {unknown} */ { x }) { console.log(x); } // error in the destructure try { } catch (/** @type {Unknown} */ { x }) { console.log(x); } // error in the destructure try { } catch (/** @type {Error} */ { x }) { } // error in the type try { } catch (/** @type {object} */ { x }) { } // error in the type }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocConstructorFunctionTypeReference.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @noImplicitAny: true // @Filename: jsdocConstructorFunctionTypeReference.js var Validator = function VFunc() { this.flags = "gim" }; Validator.prototype.num = 12 /** * @param {Validator} state */ var validateRegExpFlags = function(state) { return state.flags };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocFunctionType.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @noImplicitAny: true // @Filename: functions.js /** * @param {function(this: string, number): number} c is just passing on through * @return {function(this: string, number): number} */ function id1(c) { return c } var x = id1(function (n) { return this.length + n }); /** * @param {function(new: { length: number }, number): number} c is just passing on through * @return {function(new: { length: number }, number): number} */ function id2(c) { return c } class C { /** @param {number} n */ constructor(n) { this.length = n; } } var y = id2(C); var z = new y(12); z.length; /** @type {function ("a" | "b", 1 | 2): 3 | 4} */ var f = function (ab, onetwo) { return ab === "a" ? 3 : 4; } /** * @constructor * @param {number} n */ function D(n) { this.length = n; } var y2 = id2(D); var z2 = new y2(33); z2.length; /** * @param {function(new: D, number)} dref * @return {D} */ var construct = function(dref) { return new dref(33); } var z3 = construct(D); z3.length; /** * @constructor * @param {number} n */ var E = function(n) { this.not_length_on_purpose = n; }; var y3 = id2(E); // Repro from #39229 /** * @type {(...args: [string, string] | [number, string, string]) => void} */ function foo(...args) { args; } foo('abc', 'def'); foo(42, 'abc', 'def');
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocFunction_missingReturn.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @strict: true // @Filename: /a.js /** @type {function(): number} */ function f() {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocImplements_class.ts
TypeScript
// @allowJs: true // @checkJs: true // @declaration: true // @emitDeclarationOnly: true // @outDir: ./out // @Filename: /a.js class A { /** @return {number} */ method() { throw new Error(); } } /** @implements {A} */ class B { method() { return 0 } } /** @implements A */ class B2 { /** @return {string} */ method() { return "" } } /** @implements {A} */ class B3 { } var Ns = {}; /** @implements {A} */ Ns.C1 = class { method() { return 11; } } /** @implements {A} */ var C2 = class { method() { return 12; } } var o = { /** @implements {A} */ C3: class { method() { return 13; } } } class CC { /** @implements {A} */ C4 = class { method() { return 14; } } } var C5; /** @implements {A} */ Ns.C5 = C5 || class { method() { return 15; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocImplements_interface.ts
TypeScript
// @allowJs: true // @checkJs: true // @declaration: true // @emitDeclarationOnly: true // @outDir: ./out // @Filename: /defs.d.ts interface A { mNumber(): number; } // @Filename: /a.js /** @implements A */ class B { mNumber() { return 0; } } /** @implements {A} */ class B2 { mNumber() { return ""; } } /** @implements A */ class B3 { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocImplements_interface_multiple.ts
TypeScript
// @allowJs: true // @checkJs: true // @declaration: true // @emitDeclarationOnly: true // @outDir: ./out // @Filename: /defs.d.ts interface Drawable { draw(): number; } interface Sizable { size(): number; } // @Filename: /a.js /** * @implements {Drawable} * @implements Sizable **/ class Square { draw() { return 0; } size() { return 0; } } /** * @implements Drawable * @implements {Sizable} **/ class BadSquare { size() { return 0; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocImplements_missingType.ts
TypeScript
// @allowJs: true // @checkJs: true // @declaration: true // @emitDeclarationOnly: true // @outDir: ./out // @Filename: /a.js class A { constructor() { this.x = 0; } } /** @implements */ class B { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocImplements_namespacedInterface.ts
TypeScript
// @allowJs: true // @checkJs: true // @declaration: true // @emitDeclarationOnly: true // @outDir: ./out // @Filename: /defs.d.ts declare namespace N { interface A { mNumber(): number; } interface AT<T> { gen(): T; } } // @Filename: /a.js /** @implements N.A */ class B { mNumber() { return 0; } } /** @implements {N.AT<string>} */ class BAT { gen() { return ""; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocImplements_properties.ts
TypeScript
// @allowJs: true // @checkJs: true // @declaration: true // @emitDeclarationOnly: true // @outDir: ./out // @Filename: /a.js class A { constructor() { this.x = 0; } } /** @implements A*/ class B {} /** @implements A*/ class B2 { x = 10 } /** @implements {A}*/ class B3 { constructor() { this.x = 10 } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocImplements_signatures.ts
TypeScript
// @allowJs: true // @checkJs: true // @declaration: true // @emitDeclarationOnly: true // @outDir: ./out // @Filename: /defs.d.ts interface Sig { [index: string]: string } // @Filename: /a.js /** @implements {Sig} */ class B { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocImportType.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @Filename: types.d.ts declare function require(name: string): any; declare var exports: any; declare var module: { exports: any }; // @Filename: mod1.js /// <reference path='./types.d.ts'/> class Chunk { constructor() { this.chunk = 1; } } module.exports = Chunk; // @Filename: use.js /// <reference path='./types.d.ts'/> /** @typedef {import("./mod1")} C * @type {C} */ var c; c.chunk; const D = require("./mod1"); /** @type {D} */ var d; d.chunk;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocImportType2.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @Filename: types.d.ts declare function require(name: string): any; declare var exports: any; declare var module: { exports: any }; // @Filename: mod1.js /// <reference path='./types.d.ts'/> module.exports = class Chunk { constructor() { this.chunk = 1; } } // @Filename: use.js /// <reference path='./types.d.ts'/> /** @typedef {import("./mod1")} C * @type {C} */ var c; c.chunk; const D = require("./mod1"); /** @type {D} */ var d; d.chunk;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocImportTypeReferenceToClassAlias.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: mod1.js class C { s() { } } module.exports.C = C // @Filename: test.js /** @typedef {import('./mod1').C} X */ /** @param {X} c */ function demo(c) { c.s }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/jsdocImportTypeReferenceToCommonjsModule.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: ex.d.ts declare var config: { fix: boolean } export = config; // @Filename: test.js /** @param {import('./ex')} a */ function demo(a) { a.fix }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University