Skip to content

Releases: GoogleFeud/ts-macros

v1.3.1

29 Apr 20:07
Compare
Choose a tag to compare

Bug fixes

Changes

  • $$escape macro and Save marker can now work outside blocks.

Additions

  • Replaced the $$loadJSONAsEnv with a more general purpose macro $$readFile, which allows you to get a file's contents.

v.1.3.0

20 Apr 21:51
Compare
Choose a tag to compare

Bug fixes

  • $$escape wasn't hygienic like it was shown in the docs.
  • Expanding of object / array literal access is a lot more sparing, and will always expand to the correct thing (never the object / array literal expression itself).
  • Fixed a lot of other little rare errors.

Changes

  • The $$ident macro will now use hygienic values if possible:
function $example() {
  const val = 15;
  console.log($$ident!(val));
}

$example!();

// Now transpiles to:
const val_1 = 15;
console.log(val_1);

Additions

  • Macros can now have statement as their parameters by using the macro as a label. You can read more about this feature in the docs.
// Wraps a block in a try/catch, ignoring the error
function $TrySilence(info: BlockLabel) {
    try {
        $$inlineFunc!(info.statement);
    } catch(err) {};
}

if (...) TrySilence: {
  //...
}

// Transpiles to:
if (...) {
    try {
        //...
    }
    catch (err) { };
}

v1.2.0

11 Apr 20:45
Compare
Choose a tag to compare

Changes

  • Removed AsRest marker, and instead made repetitions more flexible - you can now provide an array of array literals to any repetition, to make it repeat over all of the literals:
function $showcase(a: Array<string>, b: Array<number>, c: { values: [Array<number>] }) {
    +["+", [a, b, c.values[0]], (number: number|string) => number];
}
console.log($showcase!(["a", "b", "c", "d"], [1, 2, 3], { values: [[1, 2, 3]]}))
// Turns to:
console.log("abcd123123");
  • Removed the $$import built-in macro.
  • Removed , from the repetition separators and replaced it with () (comma list expression)
  • Errors coming from the transformer are now formatted like regular typescript diagnostics are.

Additions

  • Added a $$ts built-in macro which turns strings into typescript code.
  • Added an $$escape built-in macro which puts code inside the parent scope if necessary:
function $test(arg: string) {
    $$escape!(() => {
        console.log("Instead of this macro expanding to an IIFE, it will expand to the returned value.");
    });
    return arg + "456";
}

(() => {
    const array = $test!("123");
})();

// Transpiles to:
(() => {
    console.log("Instead of this macro expanding to an IIFE, it will expand to the returned value.");
    const array = "123456";
})();
  • Added a $$includes built-in macro which checks if a value is included in an array / string literal.
  • Added a $$slice built-in macro which slices an array / string literal.
  • Added a $$typeToString built-in macro which turns any type to a string literal.
  • Added a $$propsOfType built-in macro which expands to an array literal containing all the property names of a type.
  • Added a Save marker, which always saves the provided expression in a variable with a unique name.
  • Almost every binary and unary operation can now be computed at transpile-time.
  • Macro function declarations now act more like regular functions - you can re-define macro functions in different blocks:
export function $map() {
    return 1;
}
function test() {
    function $map(msg: string) {
        return msg + " World!";
    }
    $map!("Hello");
}
$map!();
// Turns to:
function test() {
    return "Hello World!";
}
1;

v1.1.0

16 Feb 16:48
Compare
Choose a tag to compare

Changes

  • Moved documentation from the readme to github pages.

Additions

  • Added a Var marker which allows you to store expressions inside a variable.
  • Added an $$err built-in macro which throws an error during compilation.
  • Added an $$import built-in macro which creates imports.
  • Object / array accessing expressions are now replaced with literals as long as an the object / array is a literal.