babel/babylon

The use of the $ (dollar) symbol throws an error

aissaghouti opened this issue · 4 comments

Hi there,

I use a translator module angular-gettext-tools which uses babylon to extract the strings. I have the following error "Error parsing app/controllers/somefile.js at line 3179 column 123".

And here is the accused line: $gt: new Date(new Date(from).setHours(00, 00, 00, 999)).

I think it's related to the using of $ (symbol used for MongoDB queries). Because when I remove the $gt and $lt lines, no error is logged.

Input Code (source file)

var options = {
    query: {
        personID: myPersonID,
        productID: myProductID,
        orderDate: {
            $gt: new Date(new Date(from).setHours(00, 00, 00, 999)),
            $lt: new Date(new Date(to).setHours(23, 59, 59, 999))
        }
    },
    limit: 1000
};

Babylon/Babel Configuration (from angular-gettext-tools code)

babylon.parse(src, { sourceType: 'module', plugins: [
    'jsx',
    'objectRestSpread',
    'decorators',
    'classProperties',
    'exportExtensions',
    'functionBind'
  ]
});

Expected Behavior

Babylon faces a $ symbol and works normally.

Current Behavior

Babylon reads $gt, do something with it and throws an error.

Your Environment

software version
Babylon 6.17.0
node 6.2.2
npm 3.10.9
Operating System OS X
hzoo commented

Hey @aissaghouti! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@aissaghouti thanks for the report, I believe it actually has to do with 00 and sourceType: 'module':

https://astexplorer.net/#/gist/fd4a926b89b0f6aedf1d31f36b396704/5dacb5d52116c75443c860554d104b6661e85e40

Works perfectly fine now, Thanks @existentialism !
Sorry for the inconvenience.

@aissaghouti no inconvenience!