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.

DeclarationReference: Parser does not handle certain inputs correctly

See original GitHub issue

@rbuckton I’m using this issue to track some bugs found while testing the DeclarationReference API. They are minor enough to be fixed in the same PR.

  1. The @microsoft/rush-stack-compiler-3.5 package name is not handled correctly because of the . in the name:

    // (Actual) SyntaxError: SyntaxError: Invalid Component '@microsoft/rush-stack-compiler-3.5'
    // (Expected) @microsoft/rush-stack-compiler-3.5!
    console.log(DeclarationReference.package('@microsoft/rush-stack-compiler-3.5').toString());
    
    // (Actual) @microsoft/rush-stack-compiler-3.5
    // (Expected) @microsoft/rush-stack-compiler-3.5!
    console.log(DeclarationReference.parse('@microsoft/rush-stack-compiler-3.5!').toString());
    
    // (Works correctly) @scope/package!
    console.log(DeclarationReference.parse('@scope/package!').toString());
    
  2. The parser wrongly accepts an NPM package name that is missing the !. The input should really be interpreted as a package, because @ is not a valid identifier, but packages should require the ! suffix to avoid confusion:

    // (Actual) @scope/my-package
    // (Expected) SyntaxError
    console.log(DeclarationReference.parse('@scope/my-package').toString());
    
    // (Works correctly) @scope/my-package!
    console.log(DeclarationReference.parse('@scope/my-package!').toString());
    
  3. The parser wrongly accepts identifiers containing spaces.

    // (Actual) a.b c.d
    // (Expected) SyntaxError
    console.log(DeclarationReference.parse('a.b c.d').toString());
    

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rbucktoncommented, Aug 2, 2019

Do you have any objection to simply scanning forwards until we find the ! delimiter and then parsing the two halves separately?

No, its probably not a problem. I took a look and should have a PR up shortly.

0reactions
octogonzcommented, Aug 7, 2019

@rbuckton I validated that issues (1) and (2) are fixed, but issue (3) still repros:

// (Actual) a.b c.d
// (Expected) SyntaxError
console.log(DeclarationReference.parse('a.b c.d').toString());

I’m going to go ahead and merge your PR, though, so we can unblock https://github.com/microsoft/web-build-tools/pull/1406. I’ll open a separate issue for this (relatively minor) edge case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[api-extractor] Add an experimental new ApiItem ... - GitHub
It is marked as @beta, but the values are written in the .api.json file format for ... DeclarationReference: Parser does not handle certain...
Read more >
CS 301: Roost Compiler Front End
In this project stage, you will implement the syntax analysis and semantic analysis components (the “front end”) of the Roost compiler. You will...
Read more >
Explanation of the error messages for the W3C Markup Validator
This error may appear when the validator receives an empty document. Please make sure that the document you are uploading is not empty,...
Read more >
TSDoc
TSDoc is a proposal to standardize the doc comments used in TypeScript code, ... Here's some examples of popular tools that need to...
Read more >
Good practices for parsing user inputs with special characters?
However, the system is designed to handle more complex queries. As you can see from the previous query, the data field name and...
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