Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require some babel parser configuration #17

Closed
beenotung opened this issue Jul 20, 2020 · 2 comments
Closed

require some babel parser configuration #17

beenotung opened this issue Jul 20, 2020 · 2 comments

Comments

@beenotung
Copy link

I tried to use typedraft on a file that is using decorator function, got error complaining about babel parser configuration. What is the suggested way to deal with this issue?

Typedraft source code:

@Injectable()
export class CoreService {
  ...
}

Error message:

$ node_modules/.bin/td src/core/core.service-2.tsx
(node:823896) UnhandledPromiseRejectionWarning: SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators' (32:0)
    at Object._raise (/path/to/project/node_modules/.pnpm/@babel/parser@7.10.4/node_modules/@babel/parser/lib/index.js:757:17)
    at Object.raiseWithData (/path/to/project/node_modules/.pnpm/@babel/parser@7.10.4/node_modules/@babel/parser/lib/index.js:750:17)
    at Object.expectOnePlugin (/path/to/project/node_modules/.pnpm/@babel/parser@7.10.4/node_modules/@babel/parser/lib/index.js:8849:18)
    at Object.parseDecorator (/path/to/project/node_modules/.pnpm/@babel/parser@7.10.4/node_modules/@babel/parser/lib/index.js:11385:10)
    at Object.parseDecorators (/path/to/project/node_modules/.pnpm/@babel/parser@7.10.4/node_modules/@babel/parser/lib/index.js:11367:30)
    at Object.parseStatement (/path/to/project/node_modules/.pnpm/@babel/parser@7.10.4/node_modules/@babel/parser/lib/index.js:11200:12)
    at Object.parseBlockOrModuleBlockBody (/path/to/project/node_modules/.pnpm/@babel/parser@7.10.4/node_modules/@babel/parser/lib/index.js:11778:25)
    at Object.parseBlockBody (/path/to/project/node_modules/.pnpm/@babel/parser@7.10.4/node_modules/@babel/parser/lib/index.js:11764:10)
    at Object.parseTopLevel (/path/to/project/node_modules/.pnpm/@babel/parser@7.10.4/node_modules/@babel/parser/lib/index.js:11134:10)
    at Object.parse (/path/to/project/node_modules/.pnpm/@babel/parser@7.10.4/node_modules/@babel/parser/lib/index.js:12836:10)
(node:823896) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:823896) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@mistlog
Copy link
Owner

mistlog commented Jul 20, 2020

Thanks for reporting this.

It can be fixed by adding ["decorators",{ "decoratorsBeforeExport": true }] in https://github.com/mistlog/typedraft/blob/0.2.2/src/common/utility.ts#L38.

i.e.

return parse(code, {
      sourceType: "module",
-     plugins: ["typescript", "jsx", "optionalChaining"],
+     plugins: ["typescript", "jsx", ["decorators",{ "decoratorsBeforeExport": true }]],
 });

I will fix it in next release.

mistlog added a commit that referenced this issue Jul 21, 2020
mistlog added a commit that referenced this issue Jul 21, 2020
@mistlog
Copy link
Owner

mistlog commented Jul 22, 2020

now it's fixed in 0.2.3: https://github.com/mistlog/typedraft/releases/tag/0.2.3

@mistlog mistlog closed this as completed Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants