Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollback tsconfig.base.json's target to es5 for transformer libraries #52826

Closed
5 tasks done
samchon opened this issue Feb 17, 2023 · 5 comments
Closed
5 tasks done

Rollback tsconfig.base.json's target to es5 for transformer libraries #52826

samchon opened this issue Feb 17, 2023 · 5 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@samchon
Copy link

samchon commented Feb 17, 2023

Suggestion

πŸ” Search Terms

  • target
  • tsconfig.json
  • v5
  • ttypescript
  • ts-patch
  • transformer

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Hope to keep es5 taget build for transformer libraries.

Until v4.9, TypeScript had been built as es5. However, after v5 update, it has been changed from es5 to `es2018.

"target": "es5",

"target": "es2018",

I understand the reason why updating the build target, however, it may be a critically damage on transformer libraries.

Looking at source code of transformer libraries like ttypescript and ts-patch, they are supporting transform plugin through hacking TypeScript source code like below. They're utilizing and strongly dependent on characteristics of es5 target build.

// HACKING CODE FROM TTYPESCRIPT
fs
    .readFileSync(tscFileName, 'utf8')
    .replace(
        major >= 4 && minor >= 9
            ? /^[\s\S]+(\(function \(ts\) {\s+var StatisticType;[\s\S]+)$/
            : /^[\s\S]+(\(function \(ts\) \{\s+function countLines[\s\S]+)$/, 
        '$1'
    );

// HACKED CODE IN LIB/TSC.JS
var ts;
(function (ts) {
    var StatisticType;
    (function (StatisticType) {
        StatisticType[StatisticType["time"] = 0] = "time";
        StatisticType[StatisticType["count"] = 1] = "count";
        StatisticType[StatisticType["memory"] = 2] = "memory";
    })(StatisticType = ts.StatisticType || (ts.StatisticType = {}));
    function countLines(program) {
        var counts = getCountsMap();
        ts.forEach(program.getSourceFiles(), function (file) {
            var key = getCountKey(program, file);
            var lineCount = ts.getLineStarts(file).length;
            counts.set(key, counts.get(key) + lineCount);
        });
        return counts;
    }

πŸ’» Use Cases

Threfore, I hope you TypeScript language developers to keep the es5 target build.

As you know, so many TypeScript lovers are enjoying transformeer libraries like typescript-transform-paths. I am also developing transformer based libraries like typia and nestia for many years. I do not want to lose transformer API, and do not want to give up maintaining my open source libraries, either.

Please keep the target build option as es5.

@samchon
Copy link
Author

samchon commented Feb 17, 2023

p.s) If hard to rollback the build option, is it possible support the transform plugin by TypeScript itself?

@jakebailey
Copy link
Member

jakebailey commented Feb 17, 2023

The change in the output has nothing to do with the target being changed from ES5 to ES2018; the code you have above only works because TypeScript used to be authored using namespaces, which produced a series of:

var ts;
(function (ts) {
  ts.something = ...
})(ts)
var ts;
(function (ts) {
  ts.somethingElse = ...
})(ts)

But now we're modules, which simply do not produce that code, and additionally do not allow the API to be overwritten at runtime. I don't see us reverting that change.

Any package which patches typescript is already fragile because any aspect of our output could change. This change is just one potential way that this could have broken.

Those who have to patch typescript will need to:

  • Find another way to achieve the same goal, i.e. use our API to implement tooling.
  • Take the approach used by yarn and fork this repo, producing patches from the two outputs to apply to release builds.
  • Take the approach used by prettier (in an upcoming version) and update the patching code into some other potentially fragile modification.

Or, of course, give a proposal about what to change in TS to allow these sorts of things, though I believe all of the major reasons to patch typescript already have corresponding issues.

@samchon
Copy link
Author

samchon commented Feb 17, 2023

@jakebailey Thanks for fast replying. I just hope ttypescript and ts-patch to support TS 5.0 following your guide.

This question is by just my curiosity. Is there some reason that TypeScript is not supporting transform plugin by itself?

@jakebailey
Copy link
Member

See #14419 and #16607.

@RyanCavanaugh RyanCavanaugh added the External Relates to another program, environment, or user action which we cannot control. label Feb 17, 2023
@nonara
Copy link

nonara commented Feb 17, 2023

@samchon Jake is correct. This issue can be closed.

ts-patch will continue to support TS5+; however, I have been holding off until we were closer to the release date due to being personally backlogged and to avoid having to redo work while there are still moving parts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

4 participants