microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.06k stars 12.37k forks source link

Crashes on transform and parse (from assertion/debug failures) #58924

Open Roise-yue opened 2 months ago

Roise-yue commented 2 months ago

🔎 Search Terms

Debug Failure,modifierVisitor

🕗 Version & Regression Information

⏯ Playground Link

No response

💻 Code

I did not use tsc to execute any ts programs, but instead used the command "node --max-old-space-size=10240 $(which tsc)" to increase the memory of node.js. When the version of tsc is between 5.3 and 5.4.5, the debugging error message is in “error message 1 "of "Actual behavior", and when the version of tsc is between 4.7 and 5.2, the debugging error message is in "error message 2" of "Actual behavior". I did not test versions before version 4.7 (The relevant version and configuration information are written in "Additional information about the issue")

🙁 Actual behavior

error message 1: /usr/lib/node_modules/typescript/lib/tsc.js:118651 throw e; ^

Error: Debug Failure. Use modifierVisitor instead. at visitor (/usr/lib/node_modules/typescript/lib/tsc.js:90424:22) at visitArrayWorker (/usr/lib/node_modules/typescript/lib/tsc.js:85608:49) at visitNodes2 (/usr/lib/node_modules/typescript/lib/tsc.js:85579:19) at visitEachChildOfVariableStatement (/usr/lib/node_modules/typescript/lib/tsc.js:86379:7) at visitEachChild (/usr/lib/node_modules/typescript/lib/tsc.js:85796:33) at visitVariableStatement (/usr/lib/node_modules/typescript/lib/tsc.js:90639:25) at visitor (/usr/lib/node_modules/typescript/lib/tsc.js:90435:16) at visitArrayWorker (/usr/lib/node_modules/typescript/lib/tsc.js:85608:49) at visitNodes2 (/usr/lib/node_modules/typescript/lib/tsc.js:85579:19) at visitLexicalEnvironment (/usr/lib/node_modules/typescript/lib/tsc.js:85635:16)

error message 2: /usr/lib/node_modules/typescript/lib/tsc.js:2099 throw e; ^

Error: Debug Failure. Expected 23 <= 22 at attachFileToDiagnostic (/usr/lib/node_modules/typescript/lib/tsc.js:15670:30) at Object.attachFileToDiagnostics (/usr/lib/node_modules/typescript/lib/tsc.js:15684:42) at parseSourceFileWorker (/usr/lib/node_modules/typescript/lib/tsc.js:25347:46) at Object.parseSourceFile (/usr/lib/node_modules/typescript/lib/tsc.js:25183:26) at Object.createSourceFile (/usr/lib/node_modules/typescript/lib/tsc.js:25087:29) at Object.getSourceFile (/usr/lib/node_modules/typescript/lib/tsc.js:95276:44) at compilerHost.getSourceFile (/usr/lib/node_modules/typescript/lib/tsc.js:101685:53) at findSourceFileWorker (/usr/lib/node_modules/typescript/lib/tsc.js:97446:29) at findSourceFile (/usr/lib/node_modules/typescript/lib/tsc.js:97364:26) at /usr/lib/node_modules/typescript/lib/tsc.js:97318:85

🙂 Expected behavior

Expand the memory of node.js without any errors.

Additional information about the issue

node.js:v20.14.0 and 14.21.3(tried two versions and the result is the same) tsc:Version 4.7.2-5.4.5

package.json { "name": "tscfuzz", "version": "1.0.0", "main": "index.js", "directories": { "lib": "lib" }, "scripts": { "test": "nyc --reporter=text --reporter=lcov mocha " }, "author": "", "license": "ISC", "devDependencies": { "@babel/cli": "^7.24.7", "@babel/core": "^7.24.7", "@babel/preset-env": "^7.24.7", "@babel/preset-typescript": "^7.24.7", "jshint": "^2.13.6", "mocha": "^10.4.0", "nyc": "^15.1.0" }, "dependencies": {}, "description": "" }

tsconfig.json { "compilerOptions": { "incremental": true, "target": "es6", "lib": ["es2022"], "module": "commonjs", "sourceMap": true, "inlineSourceMap": true, "inlineSources": true, "strict": true, "skipLibCheck": true, "esModuleInterop": true, "forceConsistentCasingInFileNames": true } }

Andarist commented 2 months ago

Could you try to narrow it down? It's almost impossible to fix this without knowing what source files lead to the problem.

DanielRosenwasser commented 2 months ago

Yes, one thing you could try is to keep deleting files until you've found a culprit. Then when you've narrowed things down to as few files as possible, try to delete as many lines of code as you can.

Roise-yue commented 2 months ago

I have filtered out the ts files that can cause the above problem and located the code lines in the files that may cause errors. I have modified tsconfig.json,and used version 5.4.5 of the tsc testing program on the Ubuntu 22.04.3 LTS platform.

I have provided configuration files, TS source files, and specific error messages in this repository:https://github.com/Roise-yue/tscFuzz

DanielRosenwasser commented 2 months ago

Thank you so much for finding these @Roise-yue! I'm copying those files into this comment to make it easier to follow - the transform crash is from the use of the accessor keyword used in certain spots:

// @target: esnext
// @noTypesAndSymbols: true

abstract class C1 {
    accessor accessor a: any;
    readonly accessor b: any;
    declare accessor c: any;
    accessor public d: any;
    accessor private e: any;
    accessor protected f: any;
    accessor abstract g: any;
    accessor static h: any;
    accessor i() {}
    accessor get j() { return false; }
    accessor set k(v: any) {}
    accessor constructor() {}
    accessor l?: any;
    accessor readonly m: any;
    accessor declare n: any;
}

class C2 extends C1 {
    accessor override g: any;
}

interface I1 {
    accessor a: number;
}

accessor class C3 {}
accessor interface I2 {}
accessor namespace N1 {}
accessor enum E1 {}   // Error location
accessor var V1: any;
accessor type T1 = never;
accessor function F1() {}
accessor import "x";
accessor import {} from "x";
accessor export { V1 };
accessor export default V1;
accessor import N2 = N1;

(Playground link here)

And the other error I haven't been able to verify independently, but I'm pasting it here.

// @importHelpers: true
// @target: es5
// @module: commonjs
// @moduleResolution: classic
// @experimentalDecorators: true
// @emitDecoratorMetadata: true
// @filename: external.ts
export * from "./other";
export class A { }
export class B extends A { }

declare var dec: any;

@dec
class C {
    method(@dec x: number) {    // Error location
    }
}

const o = { a: 1 };
const y = { ...o };
const { ...x } = y;

// @filename: other.ts
export const x = 1;

// @filename: script.ts
class A { }
class B extends A { }

declare var dec: any;

@dec
class C {
    method(@dec x: number) {
    }
}

// @filename: tslib.d.ts
export {}