Skip to content

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

@cedx

Description

@cedx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions