jashkenas / jashkenas/coffeescript

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

Open
#5,470 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
CoffeeScript
Stars
16.6k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

CoffeeScript supports import assertions:

```coffee
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`):

```coffee
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:

```coffee
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

Contributor guide

Open the contributing guide

Research direction

Reproduce the reserved-word error from the src/cli.coffee example using CoffeeScript 2.7.0 and Node.js 23.1.0, then trace the parser handling of import assertions and the `with` keyword. Add coverage for `import file from "./file.json" with {type: "json"}` and confirm compilation succeeds without the current error.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript, node.js
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.