Skip to content

Commit

Permalink
feat: 🚀add locations validating in static method
Browse files Browse the repository at this point in the history
  • Loading branch information
TyrealHu committed Jun 14, 2023
1 parent 47465b5 commit e707b64
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ export {
})
```

## Notice
- You have to enable options.locations while using acorn-typescript
```ts
acorn.parse(input, {
sourceType: 'module',
ecmaVersion: 'latest',
// here
locations: true
})
```

## SUPPORTED
- Typescript normal syntax
- Support to parse TypeScript [Decorators](https://www.typescriptlang.org/docs/handbook/decorators.html)
Expand Down
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5058,6 +5058,12 @@ function tsPlugin(options?: {
}

static parse(input: string, options: Options) {
if (options.locations === false) {
throw new Error(`You have to enable options.locations while using acorn-typescript`)
} else {
options.locations = true
}

const parser = new this(options, input)
if (dts) {
parser.isAmbientContext = true
Expand All @@ -5066,6 +5072,12 @@ function tsPlugin(options?: {
}

static parseExpressionAt(input: string, pos: number, options: Options) {
if (options.locations === false) {
throw new Error(`You have to enable options.locations while using acorn-typescript`)
} else {
options.locations = true
}

const parser = new this(options, input, pos)
if (dts) {
parser.isAmbientContext = true
Expand Down

0 comments on commit e707b64

Please sign in to comment.