Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* @copyright 2014 Elan Shanker. All rights reserved.
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
var globals = require("globals");
//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
module.exports = {
builtin: globals.builtin,
browser: {
globals: globals.browser
},
node: {
globals: globals.node,
ecmaFeatures: {
globalReturn: true
}
},
commonjs: {
globals: globals.commonjs,
ecmaFeatures: {
globalReturn: true
}
},
worker: {
async function main() {
const glossary = require('crowdin-glossary')({ project: 'electron' })
// JavaScript builtins like Array, Map, String, etc
Object.keys(globals.builtin).forEach(term => {
if (Object.keys(glossary.entries).includes(term)) return
glossary.add(
term,
'This is a JavaScript builtin and should usually not be translated.'
)
})
// Electron API names
electronApis.forEach(api => {
glossary.add(
api.name,
`This is an Electron ${api.type} and should usually not be translated`
)
})
// Electron instance methods and properties
function findGlobalsFromEnvironments(environments: Array): Array {
const result = Object.keys(globals.builtin);
environments.forEach((environment: string) => {
const envGlobals = globals[environment];
if (!envGlobals) {
return;
}
result.push(...Object.keys(envGlobals));
});
return result;
}
create(context) {
const config = context.options[0] || {};
const exceptions = new Set(config.exceptions || []);
const modifiedBuiltins = new Set(
Object.keys(globals.builtin)
.filter(builtin => builtin[0].toUpperCase() === builtin[0])
.filter(builtin => !exceptions.has(builtin))
);
/**
* Reports a lint error for the given node.
* @param {ASTNode} node The node to report.
* @param {string} builtin The name of the native builtin being extended.
* @returns {void}
*/
function reportNode(node, builtin) {
context.report({
node,
messageId: "unexpected",
data: {
builtin
if (cached) return cached;
this.uid = uid++;
this.parent = parentScope;
this.hub = path.hub;
this.parentBlock = path.parent;
this.block = path.node;
this.path = path;
}
/**
* Globals.
*/
static globals = Object.keys(globals.builtin);
/**
* Variables available in current context.
*/
static contextVariables = [
"arguments",
"undefined",
"Infinity",
"NaN"
];
/**
* Traverse node with current scope and path.
*/
import globalScope from 'globals'
import {namedTypes} from './build-types'
const browserAPIs = Object.keys(globalScope.browser)
const builtinAPIs = Object.keys(globalScope.builtin)
export const isIdentifier = n => namedTypes.Identifier.check(n)
export const isLiteral = n => namedTypes.Literal.check(n)
export const isExpressionStatement = n => namedTypes.ExpressionStatement.check(n)
export const isObjectExpression = n => namedTypes.ObjectExpression.check(n)
export const isThisExpression = n => namedTypes.ThisExpression.check(n)
export const isNewExpression = n => namedTypes.NewExpression.check(n)
export const isSequenceExpression = n => namedTypes.SequenceExpression.check(n)
export const isBinaryExpression = n => namedTypes.BinaryExpression.check(n)
export const isExportDefaultStatement = n => namedTypes.ExportDefaultDeclaration.check(n)
export const isMemberExpression = n => namedTypes.MemberExpression.check(n)
export const isBrowserAPI = ({name}) => browserAPIs.includes(name)
export const isBuiltinAPI = ({name}) => builtinAPIs.includes(name)
export const isRaw = n => n && n.raw
}
scopeCache.set(node, this);
this.uid = uid++;
this.block = node;
this.path = path;
this.labels = new Map();
}
/**
* Globals.
*/
static globals = Object.keys(globals.builtin);
/**
* Variables available in current context.
*/
static contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
get parent() {
const parent = this.path.findParent(p => p.isScope());
return parent && parent.scope;
}
get parentBlock() {
return this.path.parent;
}