Skip to content

Releases: GoogleFeud/ts-macros

v2.6.1

20 Jul 13:04
Compare
Choose a tag to compare

Changes

  • Support for typescript 5.5.x

v2.6.0

09 Oct 15:30
Compare
Choose a tag to compare

Additions

  • $$typeMetadata built-in macro which gathers information on the provided type. This includes:
    • Properties and their names, whether they're optional or not, their stringified types, and their JSDoc tags.
    • Methods and their names, their return type, their parameter names and types, and their JSDoc tags.
  • You can now access the type of repetition elements (#78):
    function $compareTypes<T extends unknown[]>(a: T, b: T) {
        +["[]", [a, b], <AT, BT>(aEl: AT, bEl: BT) => $$typeToString!<AT>() === $$typeToString!<BT>()];
    }
    
    console.log($compareTypes!(["abc", 2, false, 3], ["abc", 2, true, false]));
    // Transpiles to:
    console.log([true, true, false, false]);
  • Logging to the console in the playground now displays the messages in a side-panel.

Changes

  • Improved literal reduction with the logical OR and AND operators.
    • true literal || non literal, will be reduced to the true literal expression.
    • false literal || non literal, will be reduced to the non literal expression.
    • true literal && non literal, will be reduced to the non literal expression.
    • false literal && non literal, will be reduced to the false literal expression.

Bug fixes

  • Fixed the call function not being present in the RawContext interface in the playground.
  • Invalid code like {a: 1}.b; can longer be generated.
  • Fixed #77.

Deprecations

Some parts of this library negatively impact the transformer's performance and make the source code more complex to maintain while serving a fairly niche purpose. If you find these features useful, please create an issue about it! If enough people use them they won't be removed.

  • $$comptime macro - While cool to have something similar to Zig's comptime macros, it's way too limited. It can realistically only be used to validate arguments passed to functions, which should be done during runtime anyway.
  • $$loadEnv macro - Requires an optional dependency, a similar result can be achieved using the $$readFile macro by putting your configuration in a JSON file.
  • $$propsOfType macro - In favor of the $$typeMetadata macro.

v2.5.0

25 Sep 14:39
Compare
Choose a tag to compare

Additions

  • ts-macros CLI: A CLI tool now comes with ts-macros, that allows you to transform your entire project to expand all macros, and then optionally transpile to javascript. It also features a watch option, which should be used instead other watchers. Read more here.
  • Support for typescript version 5.2.x

v2.4.2

20 Sep 07:24
Compare
Choose a tag to compare

Additions

  • Added an option to $$typeToString that makes it so some parts of the type don't get ellipsized. (#74)

Bug fixes

  • Fixed various playground bugs
  • Fixes #72
  • Fixes #73

v2.4.1

04 Sep 14:11
Compare
Choose a tag to compare

Changes

  • Removed type definitions of the deprecated methods in the playground
  • $$define now has the correct return type (void instead of number)

Bug fixes

  • Fixed #69
  • Fixed SyntaxKind enum members not expanding to numeric literals in macros in the playground.

v2.4.0

25 Aug 13:36
Compare
Choose a tag to compare

Additions

  • A second experimental transformer, type-resolver, that transpiles your code to typescript with all macros expanded before transpiling it to javascript. This means you can use types or exported values generated by macros in your code!
    • The transformer also works in your editor if you patch the tsserver file with ts-patch.
      show
    • This transformer can only be used with ts-patch.
  • You can now export the variables defined by the $$define macro by passing a fourth parameter.

Changes

  • You can no longer change the name of classes/enums/functions by giving them the same name as a maco parameter, use macro variables from now on:
    function $setPropName(names: string) {
      const $name = $$ident!(names);
      return class $name {
        $test: string = ""
      }
    }
  • Removed the $$getStore and $$setStore built-in macro.
    • Use macro variables instead: const $value = 123;
  • Removed the $$inlineFunc built-in macro.
    • Use the $$inline macro instead.

Bug fixes

v2.3.1

29 Jul 13:55
Compare
Choose a tag to compare

Bug fixes

v2.3.0

17 Jul 13:31
Compare
Choose a tag to compare

Additions

  • Added require function to the raw context (#58)
  • Support for tagged template literal macros (#57):
function $template(strs: TemplateStringsArray, ...elements: number[]) {
   return +["+", [strs, elements], (string: string, el: number) => string + (el ? el + 1 : "")]
}
// Call
$template!`Hello ${1} world ${2}`;
// Result
"Hello 2 world 3";

Changes

  • Remove ttypescript usage example (#59)

Bug fixes

v2.2.2

14 Jun 13:52
Compare
Choose a tag to compare
  • Support for typescript 5.x

Additions

  • Macro labels can now be used on variable declarations.

Bug fixes

v2.2.1

04 Apr 16:21
Compare
Choose a tag to compare

Bug fixes