Skip to content

Import attributes break message exporting #4489

Closed
@brawaru

Description

@brawaru

Which package?

@formatjs/cli@6.2.12

Describe the bug

When import attributes are used in the code, @formatjs/cli fails to extract messages despite tsc being able to successfully check the file.

The following errors are printed to console:

[@formatjs/cli] [WARN] Error: index.mts:2:43 - error TS1005: ';' expected.

2 import { doSomething } from './other.mjs' with { type: 'macro' }
                                            ~~~~
index.mts:2:48 - error TS1005: '(' expected.

2 import { doSomething } from './other.mjs' with { type: 'macro' }
                                                 ~
index.mts:4:1 - error TS1005: ')' expected.

4 export const msg = defineMessage({
  ~~~~~~

To Reproduce

Codesandbox URL

https://stackblitz.com/edit/node-by7zrp?file=package.json

Reproducible Steps/Repo

  1. Create file b.mts with contents like:
export function myMacro() {
  return { id: 'woo' }
}
  1. Create file a.mts with contents like:
import { defineMessage } from '@formatjs/intl'
import { myMacro } from './b.mts' with { type: 'macro' }

export const greeting = defineMessage({
  id: 'greeting',
  defaultMessage: 'Hello, {name}!',
})

export const smthnElse = myMacro()
  1. Try to extract messages from a.mts
pnpm formatjs extract a.mts --out-file output.json

Expected behavior

Extraction completes without errors and yields a file output.json with contents:

{
  "greeting": {
    "defaultMessage": "Hello, {name}!"
  }
}

Screenshots

N/A

Desktop (please complete the following information):

N/A

Smartphone (please complete the following information):

N/A

Additional context

N/D

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions