question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: decorator before export has different location with `babel`

See original GitHub issue
require("meriyah").parse('@decorator export class Bar {}', {loc: true, module: true, next: true}).body[0]
{
  type: 'ExportNamedDeclaration',
  declaration: {
    type: 'ClassDeclaration',
    id: { type: 'Identifier', name: 'Bar', loc: [Object] },
    superClass: null,
    decorators: [ [Object] ],
    body: { type: 'ClassBody', body: [], loc: [Object] },
    loc: { start: [Object], end: [Object] }
  },
  specifiers: [],
  source: null,
  loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 30 } }
}

We have column 0 ~ 30

While @babel/parser has column 11 ~ 30

require("@babel/parser").parse('@decorator export class Bar {}', {sourceType:'module', plugins:[['decorators', {decoratorsBeforeExport: true}]]}).program.body[0].loc
SourceLocation {
  start: Position { line: 1, column: 11 },
  end: Position { line: 1, column: 30 },
  filename: undefined,
  identifierName: undefined
}

Should we align with them?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
KFlashcommented, Oct 27, 2020

Interesting! And I worked in Hong Kong for 7 years and I only head mandaring all the time, so I guess different dialects, and I starting to be rusty. Better in speaking it rather than writing it 😃

1reaction
3cpcommented, Oct 27, 2020

Few other parsers are same as babel, I guess I need to fix ours.

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel 7 Using the export keyword between a decorator and a ...
Technically, you just move export to the bottom of the class. If you have a lot of classes, that solution is not the...
Read more >
TC39 Standards Track Decorators in Babel
The decorator proposal has gone back and forth on this question: should decorators come before or after the export keyword?
Read more >
Understanding JavaScript decorators - LogRocket Blog
Learn about JavaScript's function decorators and class decorators as well as how you can create clean and reusable decorators.
Read more >
@babel/plugin-proposal-decorators | Yarn - Package Manager
Changelog. Tags: :boom: [Breaking Change]; :eyeglasses: [Spec Compliance]; :rocket: [New Feature] ...
Read more >
Updating the Decorators Proposal for the Holidays - SitePen
Photo by Annie Spratt on Unsplash The Ecma TC39 committee, which standardizes the JavaScript language (officially known as ECMAScript), has ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found