bigfish / vim-js-context-coloring

JavaScript Context Coloring in Vim
MIT License
151 stars 8 forks source link

ES6 modules -> syntax error #18

Closed jskeate closed 9 years ago

jskeate commented 9 years ago

Did some looking into this myself. Seems like escope has two sourceTypes: https://github.com/estools/escope/blob/master/src/index.js#L65

If it is 'script', then import statements will cause an error. Changing this to 'module' makes it work, with the caveat that plain (non-module) JS files seem to be one context-color deeper than expected (e.g. root context is green)

edit: the last part (one deeper) might just be because of using let and the "block scope with let" flag

bigfish commented 9 years ago

Good catch! I added the sourceType:module to the escope options. Did some quick tests, perused the escope source.. looks like there's no downside to adding this option.

The color green is by default assigned to level 0 (global) so that seems correct..(white is undeclared, or implicit global) I dont see change in levels with or without this option, so I don't think there are any side effects as far as I can tell. Modules are there own scope, but it seems that in a module-defining-script, the module scope is the root scope, as a single file can only export one module, so it becomes level 0, hence green.