globalizejs / globalizejs/globalize-compiler

Give better error message on syntax errors

Open
#41 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
10
Forks
14
PR merge metrics
No merged PRs in 30d

Description

The errors generated by globalize-compiler are pretty cryptic and not useful when it fails to parse a file.

time.js
```js
import Globalize from 'globalize';

/**
* Intl Format a short time string e.g. "9:30 AM" in en-US
*/
export const formatTime = Globalize.dateFormatter({ date: 'short' });
```
```shell
globalize-compiler -l en -o en.js time.js
```

Gives the following result:
```
{...}/node_modules/globalize-compiler/node_modules/esprima/esprima.js:5702
throw e;
^
Error: Line 1: Unexpected token
at constructError ({...}/node_modules/globalize-compiler/node_modules/esprima/esprima.js:2407:21)
at createError ({...}/node_modules/globalize-compiler/node_modules/esprima/esprima.js:2426:17)
at unexpectedTokenError ({...}/node_modules/globalize-compiler/node_modules/esprima/esprima.js:2500:13)
at tolerateUnexpectedToken ({...}/node_modules/globalize-compiler/node_modules/esprima/esprima.js:2509:21)
at parseStatementListItem ({...}/node_modules/globalize-compiler/node_modules/esprima/esprima.js:3973:21)
at parseScriptBody ({...}/node_modules/globalize-compiler/node_modules/esprima/esprima.js:5490:25)
at parseProgram ({...}/node_modules/globalize-compiler/node_modules/esprima/esprima.js:5506:16)
at Object.parse ({...}/node_modules/globalize-compiler/node_modules/esprima/esprima.js:5690:23)
at Object.extractor [as extract] ({...}/node_modules/globalize-compiler/lib/extract.js:39:17)
at {...}/node_modules/globalize-compiler/bin/globalize-compiler.js:84:27 {
lineNumber: 1,
description: 'Unexpected token',
index: 0
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```

In this example it's clear that globalize-compiler doesn't support ES20153. But It doesn't tell you what file the failure is. And if the error was somewhere in the middle of the file it wouldn't necessarily be easy to discover what the issue is.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.