bennyp
bennyp2w ago

Decorators with esbuild-deno-loader

I want to compile class method decorators (ecmascript stage 3) with esbuild per the bundling docs, but I get "Unexpected token @logged" at runtime
❯ dist/bin/design-tokens-language-server
error: Uncaught SyntaxError: Invalid or unexpected token
@logged("hi")
^
at <anonymous> (file:///tmp/deno-compile-design-tokens-language-server/dist/main.js:42625:3)
❯ dist/bin/design-tokens-language-server
error: Uncaught SyntaxError: Invalid or unexpected token
@logged("hi")
^
at <anonymous> (file:///tmp/deno-compile-design-tokens-language-server/dist/main.js:42625:3)
build script:
import * as esbuild from "esbuild";
import { denoPlugins } from "@luca/esbuild-deno-loader";

import { expandGlob } from "jsr:@std/fs";

const decoder = new TextDecoder();

await esbuild.build({
plugins: [...denoPlugins()],
entryPoints: ["src/main.ts"],
outfile: "./dist/main.js",
bundle: true,
format: "esm",
});

await esbuild.stop();

const includes = await Array.fromAsync(
expandGlob("dist/*.wasm"),
(file) => `--include=${file.path}`,
);

async function compile() {
const args = [
"compile",
"--allow-all",
"--no-lock",
"--no-check",
"--no-remote",
"--no-config",
"--import-map=import-map-bundle.json",
...includes,
`--output=dist/bin/design-tokens-language-server`,
"dist/main.js",
"--stdio",
].filter((x) => typeof x === "string");
const { code, stdout, stderr } = await new Deno.Command(Deno.execPath(), {
stdout: "piped",
args,
}).output();
if (code === 0) {
console.log(`Built ${arch ?? "native"}`);
} else {
console.log(`deno ${args.join(" ")}\n`);
console.log(decoder.decode(stdout));
console.log(decoder.decode(stderr));
throw new Error(`Could not build ${arch ?? "native"}`);
}
}

await compile();
import * as esbuild from "esbuild";
import { denoPlugins } from "@luca/esbuild-deno-loader";

import { expandGlob } from "jsr:@std/fs";

const decoder = new TextDecoder();

await esbuild.build({
plugins: [...denoPlugins()],
entryPoints: ["src/main.ts"],
outfile: "./dist/main.js",
bundle: true,
format: "esm",
});

await esbuild.stop();

const includes = await Array.fromAsync(
expandGlob("dist/*.wasm"),
(file) => `--include=${file.path}`,
);

async function compile() {
const args = [
"compile",
"--allow-all",
"--no-lock",
"--no-check",
"--no-remote",
"--no-config",
"--import-map=import-map-bundle.json",
...includes,
`--output=dist/bin/design-tokens-language-server`,
"dist/main.js",
"--stdio",
].filter((x) => typeof x === "string");
const { code, stdout, stderr } = await new Deno.Command(Deno.execPath(), {
stdout: "piped",
args,
}).output();
if (code === 0) {
console.log(`Built ${arch ?? "native"}`);
} else {
console.log(`deno ${args.join(" ")}\n`);
console.log(decoder.decode(stdout));
console.log(decoder.decode(stderr));
throw new Error(`Could not build ${arch ?? "native"}`);
}
}

await compile();
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?