Skip to content

Commit e707b64

Browse files
committed
feat: 🚀add locations validating in static method
1 parent 47465b5 commit e707b64

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

‎README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ export {
5454
})
5555
```
5656

57+
## Notice
58+
- You have to enable options.locations while using acorn-typescript
59+
```ts
60+
acorn.parse(input, {
61+
sourceType: 'module',
62+
ecmaVersion: 'latest',
63+
// here
64+
locations: true
65+
})
66+
```
67+
5768
## SUPPORTED
5869
- Typescript normal syntax
5970
- Support to parse TypeScript [Decorators](https://www.typescriptlang.org/docs/handbook/decorators.html)

‎src/index.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5058,6 +5058,12 @@ function tsPlugin(options?: {
50585058
}
50595059

50605060
static parse(input: string, options: Options) {
5061+
if (options.locations === false) {
5062+
throw new Error(`You have to enable options.locations while using acorn-typescript`)
5063+
} else {
5064+
options.locations = true
5065+
}
5066+
50615067
const parser = new this(options, input)
50625068
if (dts) {
50635069
parser.isAmbientContext = true
@@ -5066,6 +5072,12 @@ function tsPlugin(options?: {
50665072
}
50675073

50685074
static parseExpressionAt(input: string, pos: number, options: Options) {
5075+
if (options.locations === false) {
5076+
throw new Error(`You have to enable options.locations while using acorn-typescript`)
5077+
} else {
5078+
options.locations = true
5079+
}
5080+
50695081
const parser = new this(options, input, pos)
50705082
if (dts) {
50715083
parser.isAmbientContext = true

0 commit comments

Comments
 (0)