简体   繁体   中英

Sublime Text: Different Snippet for JavaScript ES5 vs ES6?

I have these snippets I use regularly when writing tests in Jasmine , an example of one is;

<snippet>
  <content><![CDATA[
beforeEach(function() {
});
]]></content>
  <tabTrigger>be</tabTrigger>
  <scope>source.js</scope>
</snippet>

What I'm wondering is (possibly using the <scope> value?) if the output could be different based on the current Language between JavaScript, JavaScriptNext — ES6 Syntax, and JSX? But as far as I do, do these all share the source.js scope?

The output I would want is;

JavaScript

beforeEach(function() {

});

JavaScriptNext — ES6 Syntax, and JSX

beforeEach(() => {

});

Thanks for your time.

The scope depends on the syntax you are using for the file.
The ES6 syntax highlighters uses source.js for compatibility reasons.
babel-sublime/JavaScript (Babel).sublime-syntax
JavaScriptNext.tmLanguage/JavaScriptNext.YAML-tmLanguage
Some syntax (eg Markdown) may specify a portion of text source.js , which will then be handled by the ES6 syntax.

You could have forked JSNext syntax and use another scope, say source.js.es6 .

I recommend facelessuser/ScopeHunter for checking scopes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM