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

Support decorator syntax when parsing with babel #13

Closed
43081j opened this issue Nov 26, 2021 · 12 comments
Closed

Support decorator syntax when parsing with babel #13

43081j opened this issue Nov 26, 2021 · 12 comments

Comments

@43081j
Copy link
Owner

43081j commented Nov 26, 2021

Related to #9, we need to expose babel options so the user can specify language features they want to turn on/off.

@ai is there a recommended way to pass options to a custom syntax?

maybe we just attempt to read a .babelrc file in the working directory...

temporarily, we could add:

['decorators', {decoratorsBeforeExport: false}]

to support whats currently in the decorators spec

@ai
Copy link

ai commented Nov 26, 2021

syntax: creator(options)?

But I think JSON config parsers will not support it.

@abdonrd
Copy link

abdonrd commented Nov 26, 2021

We have this error here:

https://github.com/IBM/pwa-lit-template/compare/stylelint-14

SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators' (26:0)

@43081j
Copy link
Owner Author

43081j commented Nov 26, 2021

@abdonrd i think the fix for now is to just enable whats in the decorators proposal by default

i'll get a patch version published today, then we can figure out what to do about options in the other issue

edit:

actually, even though the current proposal says decorators come after exports, it seems typescript uses before, so ill leave it as that for now until we can pass options

@43081j
Copy link
Owner Author

43081j commented Nov 26, 2021

Fixed in #15

@43081j 43081j closed this as completed Nov 26, 2021
@43081j
Copy link
Owner Author

43081j commented Nov 26, 2021

Published in 0.1.2

@abdonrd would be good if you could give it another try. i think you'll bump into #14 though

@abdonrd
Copy link

abdonrd commented Nov 26, 2021

@43081j thanks! It works in the CLI, but not in the VSCode extension:

Screenshot 2021-11-26 at 22 57 10

Updated: https://github.com/IBM/pwa-lit-template/compare/stylelint-14

@abdonrd
Copy link

abdonrd commented Nov 26, 2021

By the way, the auto fix in the CLI also works:

Screenshot 2021-11-26 at 22 59 50

@iSokrat
Copy link

iSokrat commented Jan 30, 2023

@43081j What's about decorators which are used in usual JS, not TS? For now, plugin reports an error for decorators which follows the latest proposal

@43081j
Copy link
Owner Author

43081j commented Feb 1, 2023

i haven't had chance to look yet but i imagine we might have to somehow expose the babel options. its unlikely we can tell babel to support both decorator specs at once, so we'd have to expose the option somehow while both exist

@iSokrat
Copy link

iSokrat commented Feb 2, 2023

@43081j Yep, I agree. Actually, now I'm trying to find a way how to integrate the package and it fails on the files where decorators are used. Will it be maybe possible to somehow use babel config which is used on the whole project-level (and nested configs if exist) somehow? I saw that we are using now hardcoded values, however, for example, in my app all of them are not suitable (typescript, decoratorsBeforeExport option for decorator and jsx, although, most of them are not really disturb me for now except decorators).

export const parse: Parser<Root | Document> = (
  source: string | {toString(): string},
  opts?: Pick<ProcessOptions, 'map' | 'from'>
): Root | Document => {
  const doc = new Document();
  const sourceAsString = source.toString();
  const ast = babelParse(sourceAsString, {
    sourceType: 'unambiguous',
    plugins: [
      'typescript',
      ['decorators', {decoratorsBeforeExport: true}],
      'jsx'
    ],
    ranges: true
  });

// ....

@43081j
Copy link
Owner Author

43081j commented Feb 2, 2023

yep i think we should have an option to inherit the babelrc or at least have a way to pass babel options in.

if you could make an issue for that, that'd be appreciated. if not though, i will when im not mobile 👍

@iSokrat
Copy link

iSokrat commented Feb 3, 2023

@43081j
Created an issue #44

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

4 participants