2017-12-26 04:23:50 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const printer = require("./printer-estree");
|
2018-03-08 19:50:33 +03:00
|
|
|
const hasPragma = require("./pragma").hasPragma;
|
2018-02-08 19:06:38 +03:00
|
|
|
const options = require("./options");
|
2018-02-09 15:17:48 +03:00
|
|
|
const privateUtil = require("../common/util");
|
2017-12-26 04:23:50 +03:00
|
|
|
|
|
|
|
// Based on:
|
|
|
|
// https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
|
|
|
|
|
2018-02-09 15:17:48 +03:00
|
|
|
const locStart = function(node) {
|
|
|
|
// Handle nodes with decorators. They should start at the first decorator
|
|
|
|
if (
|
|
|
|
node.declaration &&
|
|
|
|
node.declaration.decorators &&
|
|
|
|
node.declaration.decorators.length > 0
|
|
|
|
) {
|
|
|
|
return locStart(node.declaration.decorators[0]);
|
|
|
|
}
|
|
|
|
if (node.decorators && node.decorators.length > 0) {
|
|
|
|
return locStart(node.decorators[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.__location) {
|
|
|
|
return node.__location.startOffset;
|
|
|
|
}
|
|
|
|
if (node.range) {
|
|
|
|
return node.range[0];
|
|
|
|
}
|
|
|
|
if (typeof node.start === "number") {
|
|
|
|
return node.start;
|
|
|
|
}
|
|
|
|
if (node.loc) {
|
|
|
|
return node.loc.start;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
const locEnd = function(node) {
|
|
|
|
const endNode = node.nodes && privateUtil.getLast(node.nodes);
|
|
|
|
if (endNode && node.source && !node.source.end) {
|
|
|
|
node = endNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
let loc;
|
|
|
|
if (node.range) {
|
|
|
|
loc = node.range[1];
|
|
|
|
} else if (typeof node.end === "number") {
|
|
|
|
loc = node.end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.__location) {
|
|
|
|
return node.__location.endOffset;
|
|
|
|
}
|
|
|
|
if (node.typeAnnotation) {
|
|
|
|
return Math.max(loc, locEnd(node.typeAnnotation));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.loc && !loc) {
|
|
|
|
return node.loc.end;
|
|
|
|
}
|
|
|
|
|
|
|
|
return loc;
|
|
|
|
};
|
|
|
|
|
2017-12-26 04:23:50 +03:00
|
|
|
const languages = [
|
|
|
|
{
|
|
|
|
name: "JavaScript",
|
|
|
|
since: "0.0.0",
|
|
|
|
parsers: ["babylon", "flow"],
|
|
|
|
group: "JavaScript",
|
|
|
|
tmScope: "source.js",
|
|
|
|
aceMode: "javascript",
|
|
|
|
codemirrorMode: "javascript",
|
|
|
|
codemirrorMimeType: "text/javascript",
|
|
|
|
aliases: ["js", "node"],
|
|
|
|
extensions: [
|
|
|
|
".js",
|
|
|
|
"._js",
|
|
|
|
".bones",
|
|
|
|
".es",
|
|
|
|
".es6",
|
|
|
|
".frag",
|
|
|
|
".gs",
|
|
|
|
".jake",
|
|
|
|
".jsb",
|
|
|
|
".jscad",
|
|
|
|
".jsfl",
|
|
|
|
".jsm",
|
|
|
|
".jss",
|
|
|
|
".mjs",
|
|
|
|
".njs",
|
|
|
|
".pac",
|
|
|
|
".sjs",
|
|
|
|
".ssjs",
|
|
|
|
".xsjs",
|
|
|
|
".xsjslib"
|
|
|
|
],
|
|
|
|
filenames: ["Jakefile"],
|
|
|
|
linguistLanguageId: 183,
|
|
|
|
vscodeLanguageIds: ["javascript"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "JSX",
|
|
|
|
since: "0.0.0",
|
|
|
|
parsers: ["babylon", "flow"],
|
|
|
|
group: "JavaScript",
|
|
|
|
extensions: [".jsx"],
|
|
|
|
tmScope: "source.js.jsx",
|
|
|
|
aceMode: "javascript",
|
|
|
|
codemirrorMode: "jsx",
|
|
|
|
codemirrorMimeType: "text/jsx",
|
|
|
|
liguistLanguageId: 178,
|
|
|
|
vscodeLanguageIds: ["javascriptreact"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "TypeScript",
|
|
|
|
since: "1.4.0",
|
|
|
|
parsers: ["typescript-eslint"],
|
|
|
|
group: "JavaScript",
|
|
|
|
aliases: ["ts"],
|
|
|
|
extensions: [".ts", ".tsx"],
|
|
|
|
tmScope: "source.ts",
|
|
|
|
aceMode: "typescript",
|
|
|
|
codemirrorMode: "javascript",
|
|
|
|
codemirrorMimeType: "application/typescript",
|
|
|
|
liguistLanguageId: 378,
|
|
|
|
vscodeLanguageIds: ["typescript", "typescriptreact"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "JSON",
|
|
|
|
since: "1.5.0",
|
|
|
|
parsers: ["json"],
|
|
|
|
group: "JavaScript",
|
|
|
|
tmScope: "source.json",
|
|
|
|
aceMode: "json",
|
|
|
|
codemirrorMode: "javascript",
|
|
|
|
codemirrorMimeType: "application/json",
|
2018-04-25 17:10:22 +03:00
|
|
|
extensions: [".json", ".geojson", ".JSON-tmLanguage", ".topojson"],
|
2017-12-26 04:23:50 +03:00
|
|
|
filenames: [
|
|
|
|
".arcconfig",
|
|
|
|
".jshintrc",
|
|
|
|
".eslintrc",
|
|
|
|
".prettierrc",
|
|
|
|
"composer.lock",
|
|
|
|
"mcmod.info"
|
|
|
|
],
|
|
|
|
linguistLanguageId: 174,
|
2018-04-26 19:09:36 +03:00
|
|
|
vscodeLanguageIds: ["json", "jsonc"]
|
2018-04-25 17:10:22 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "JSON5",
|
|
|
|
since: "1.13.0",
|
|
|
|
parsers: ["json5"],
|
|
|
|
group: "JavaScript",
|
|
|
|
tmScope: "source.json",
|
|
|
|
aceMode: "json",
|
|
|
|
codemirrorMode: "javascript",
|
|
|
|
codemirrorMimeType: "application/json",
|
|
|
|
extensions: [".json5"],
|
|
|
|
filenames: [".babelrc"],
|
|
|
|
linguistLanguageId: 175,
|
2018-04-26 19:09:36 +03:00
|
|
|
vscodeLanguageIds: ["json5"]
|
2017-12-26 04:23:50 +03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
const typescript = {
|
|
|
|
get parse() {
|
|
|
|
return eval("require")("./parser-typescript");
|
|
|
|
},
|
2018-02-09 15:17:48 +03:00
|
|
|
astFormat: "estree",
|
2018-03-08 19:50:33 +03:00
|
|
|
hasPragma,
|
2018-02-09 15:17:48 +03:00
|
|
|
locStart,
|
|
|
|
locEnd
|
2017-12-26 04:23:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const babylon = {
|
|
|
|
get parse() {
|
|
|
|
return eval("require")("./parser-babylon");
|
|
|
|
},
|
2018-02-09 15:17:48 +03:00
|
|
|
astFormat: "estree",
|
2018-03-08 19:50:33 +03:00
|
|
|
hasPragma,
|
2018-02-09 15:17:48 +03:00
|
|
|
locStart,
|
|
|
|
locEnd
|
2017-12-26 04:23:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const parsers = {
|
|
|
|
babylon,
|
2018-03-08 19:50:33 +03:00
|
|
|
json: Object.assign({}, babylon, {
|
|
|
|
hasPragma() {
|
2018-04-24 16:10:16 +03:00
|
|
|
return true;
|
2018-03-08 19:50:33 +03:00
|
|
|
}
|
|
|
|
}),
|
2018-04-25 17:10:22 +03:00
|
|
|
json5: babylon,
|
2017-12-26 04:23:50 +03:00
|
|
|
flow: {
|
|
|
|
get parse() {
|
|
|
|
return eval("require")("./parser-flow");
|
|
|
|
},
|
2018-02-09 15:17:48 +03:00
|
|
|
astFormat: "estree",
|
2018-03-08 19:50:33 +03:00
|
|
|
hasPragma,
|
2018-02-09 15:17:48 +03:00
|
|
|
locStart,
|
|
|
|
locEnd
|
2017-12-26 04:23:50 +03:00
|
|
|
},
|
|
|
|
"typescript-eslint": typescript,
|
|
|
|
// TODO: Delete this in 2.0
|
|
|
|
typescript
|
|
|
|
};
|
|
|
|
|
|
|
|
const printers = {
|
|
|
|
estree: printer
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
languages,
|
2018-02-08 19:06:38 +03:00
|
|
|
options,
|
2017-12-26 04:23:50 +03:00
|
|
|
parsers,
|
2018-05-09 21:23:40 +03:00
|
|
|
printers
|
2017-12-26 04:23:50 +03:00
|
|
|
};
|