Code Monkey home page Code Monkey logo

Comments (11)

nonara avatar nonara commented on August 28, 2024 3

ts 4.9.4 support is added in ts-patch v2.1.0

from ttypescript.

nonara avatar nonara commented on August 28, 2024 1

@samchon Libraries like tts and ts-patch augment the TypeScript libraries. It isn't the TS team's responsibility to modify the compiler to support our tools. The functions we modify are internal and not a part of public API, so it's on us to keep up with changes.

If this is an issue, I'll have ts-patch working later today. Unfortunately, I don't have access to modify this library, so you'll have to wait on @cevek to follow suit.

I will update in this thread when I've investigated the issue.

from ttypescript.

forinda avatar forinda commented on August 28, 2024 1

ts 4.9.4 support is added in ts-patch v2.1.0

ts 4.9.4 support is added in ts-patch v2.1.0

So downgrading typescript from ^5.x.x to ^4.x.x works 🎉

from ttypescript.

abbaty48 avatar abbaty48 commented on August 28, 2024 1

No solution yet for ts5, downgrading to 4 works

from ttypescript.

nonara avatar nonara commented on August 28, 2024 1

Latest ts-patch rc (beta) supports ts v5, and I added some functionality so you don't have to do anything major to migrate from ttypescript. Just install and use tspc instead of ttsc

Here's more detail:

from ttypescript.

Smrtnyk avatar Smrtnyk commented on August 28, 2024

It looks related to microsoft/TypeScript#51542
probably not an issue of ttypescript

from ttypescript.

DanielRosenwasser avatar DanielRosenwasser commented on August 28, 2024

4.9.4 is now out FWIW

from ttypescript.

samchon avatar samchon commented on August 28, 2024

TS has been updated to 4.9.4, but transformation is not working yet.

How about you @nonara ?

from ttypescript.

samchon avatar samchon commented on August 28, 2024

@DanielRosenwasser May I ask you one thing?

Looking at code of this ttypescript, it transforms TS source code by replacing ts.createProgram function. But after TS 4.9 patch, the transformed.createTransform function never be called. Is there any criticial change on TS not to call the createProgram function or overwrite the createProgram function variable when compiling?

export function patchCreateProgram(tsm: typeof ts, forceReadConfig = false, projectDir = process.cwd()) {
const originCreateProgram = tsm.createProgram as any;
function createProgram(createProgramOptions: ts.CreateProgramOptions): ts.Program;
function createProgram(
rootNames: ReadonlyArray<string>,
options: ts.CompilerOptions,
host?: ts.CompilerHost,
oldProgram?: ts.Program,
configFileParsingDiagnostics?: ReadonlyArray<ts.Diagnostic>
): ts.Program;
function createProgram(
rootNamesOrOptions: ReadonlyArray<string> | ts.CreateProgramOptions,
options?: ts.CompilerOptions,
host?: ts.CompilerHost,
oldProgram?: ts.Program,
configFileParsingDiagnostics?: ReadonlyArray<ts.Diagnostic>
): ts.Program {
let rootNames;
let createOpts: ts.CreateProgramOptions | undefined;
if (!Array.isArray(rootNamesOrOptions)) {
createOpts = rootNamesOrOptions as ts.CreateProgramOptions;
}
if (createOpts) {
rootNames = createOpts.rootNames;
options = createOpts.options;
host = createOpts.host;
oldProgram = createOpts.oldProgram;
configFileParsingDiagnostics = createOpts.configFileParsingDiagnostics;
} else {
options = options!;
rootNames = rootNamesOrOptions as ReadonlyArray<string>;
}
if (forceReadConfig) {
const info = getConfig(tsm, options, rootNames, projectDir);
options = info.compilerOptions;
if (createOpts) {
createOpts.options = options;
}
projectDir = info.projectDir;
}
const program: ts.Program = createOpts
? originCreateProgram(createOpts)
: originCreateProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics);
const plugins = preparePluginsFromCompilerOptions(options.plugins);
const pluginCreator = new PluginCreator(tsm, plugins, projectDir);
const originEmit = program.emit;
/**
* The emit method has the following declaration:
* https://github.com/microsoft/TypeScript/blob/bfc55b5762443c37ecdef08a3b5a4e057b4d1e85/src/compiler/builderPublic.ts#L101
* The declaration specifies 5 arguments, but it's not true. Sometimes the emit method takes 6 arguments.
*/
program.emit = function newEmit(
targetSourceFile?: ts.SourceFile,
writeFile?: ts.WriteFileCallback,
cancellationToken?: ts.CancellationToken,
emitOnlyDtsFiles?: boolean,
customTransformers?: ts.CustomTransformers,
arg?: boolean
): ts.EmitResult {
const mergedTransformers = pluginCreator.createTransformers({ program }, customTransformers);
const result: ts.EmitResult = (originEmit as any)(
targetSourceFile,
writeFile,
cancellationToken,
emitOnlyDtsFiles,
mergedTransformers,
arg
);
// todo: doesn't work with 3.7
// result.diagnostics = [...result.diagnostics, ...transformerErrors.get(program)!];
return result;
};
return program;
}
tsm.createProgram = createProgram;
return tsm;
}

from ttypescript.

nonara avatar nonara commented on August 28, 2024

@samchon I'll take a look tomorrow and work it out.

from ttypescript.

samchon avatar samchon commented on August 28, 2024

@cevek I just analyzed what makes ttypescript broken for a while. Hope my analysis to be helpful.


I'd tried hard coding special editing on tsc.js of TS and succeeded to transforming by modifing performCompilation function to be exported function. However, the performCompilation function is not exported member, but an internal function of executeCommandLine.ts file.

Therefore, to fix this bug occured after TS 4.9 update, ttypescript should update not only createProgram file, but also executeCommandLine function too.


@DanielRosenwasser Is it possible to change the executeCommandLine function provides an additional and optional prarameter that creating the Program class instance? Or can you re-patch the TS 4.9 (maybe 4.9.5) that only wrapping ts.createProgram can be working again? I think it would be really helpful for @cevek, developer of this ttypescript project and the others using this ttypescript library.

from ttypescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.