Skip to content

TypeScript accessor keyword throws rollup error: Unexpected token .... Expected * for generator, private key, identifier or async #5976

@khaosdoctor

Description

@khaosdoctor

Describe the bug

If you create a simple TypeScript file with a class like so:

class Foo {
	accessor bar: string

	constructor (s: string) {
		this.bar = s
	}
}

And try to write a test importing this file, rolloup throws an error Unexpected token bar. Expected * for generator, private key, identifier or async

Reproduction

I'm testing with the following file: https://github.com/Formacao-Typescript/projeto-3/blob/vitest/src/domain/Class.ts
And this is the test: https://github.com/Formacao-Typescript/projeto-3/blob/vitest/src/domain/Class.test.ts

If I keep the accessor keyword:
image

If I remove the keyword:
image

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 729.30 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.2.0 - ~/.asdf/installs/nodejs/22.2.0/bin/node
    Yarn: 1.22.22 - ~/.asdf/installs/nodejs/22.2.0/bin/yarn
    npm: 10.7.0 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 9.4.0 - ~/.asdf/installs/nodejs/22.2.0/bin/pnpm
    bun: 1.0.4 - ~/.asdf/shims/bun
    Watchman: 2024.05.06.00 - /opt/homebrew/bin/watchman
  Browsers:
    Safari: 17.5
  npmPackages:
    @vitest/coverage-v8: ^1.6.0 => 1.6.0 
    @vitest/ui: ^1.6.0 => 1.6.0 
    vitest: ^1.6.0 => 1.6.0

Used Package Manager

npm

Validations

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