jashkenas/coffeescript

Allow `import file from "./file.json" with {type: "json"}` (i.e. import attributes)

Opened this issue · 0 comments

cedx commented

CoffeeScript supports import assertions:

import file from "./file.json" assert {type: "json"}

But the spec was replaced by import attributes (i.e. the assert keyword has been rewritten as with):

import file from "./file.json" with {type: "json"}

The new spec is currently at stage 3, and recently marked as stable in Node.js.
https://nodejs.org/api/esm.html#import-attributes

It would be cool if CoffeeScript supported the new syntax.
The alternative is pretty cumbersome:

import {readFileSync} from "node:fs"
import {join} from "node:path"
file = JSON.parse readFileSync join(import.meta.dirname, "./file.json"), "utf8"

Expected Behavior

No error when using import attributes.

Current Behavior

[...]\src\cli.coffee:4:35: error: reserved word 'with'
import pkg from "../package.json" with {type: "json"}

Environment

  • CoffeeScript version: 2.7.0
  • Node.js version: 23.1.0