Skip to content

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

Closed
@samchon

Description

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.

Metadata

Assignees

No one assigned

    Labels

    ExternalRelates to another program, environment, or user action which we cannot control.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions