Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function validateJSXElement(element, context) {
if (isElementMarker(element)) {
// TODO: unified error handling showing source of exception
// and context, including line/character positions.
throw new Error("Found a nested element marker in " + escodegen.generate(context.root));
}
if (isTag(element) && hasUnsafeAttributes(element)) {
assertI18nId(element);
} else if (isComponent(element)) {
let name = elementName(element);
let count = context.componentsWithoutIds[name];
if (count === undefined) {
context.componentsWithoutIds[name] = 0;
}
context.componentsWithoutIds[name]++;
}
validateChildren(element.children, context);
}
function isExtractableAttribute(element, attribute) {
let value = attributeValue(attribute);
let attributeIsWhitelisted = isWhitelistedAttribute(element, attribute);
if (attributeIsWhitelisted && !value) {
console.warn("Ignoring non-literal extractable attribute:", escodegen.generate(attribute));
}
return value && attributeIsWhitelisted;
}
function generate(ast) {
return escodegen.generate(ast.toJS()).trim();
}
var generateCode = function generateCode(ast) {
var astWithComments = escodegen.attachComments(ast, ast.comments, ast.tokens);
return escodegen.generate(astWithComments, {
comment: true,
format: { index: { style: ' ' } }
});
};
function generate(ast) {
return escodegen.generate(ast.toJS()).trim();
}
private generateCode (sourceCode: string, astTree: ESTree.Program): IGeneratorOutput {
const escodegenParams: escodegen.GenerateOptions = {
...JavaScriptObfuscatorInternal.escodegenParams
};
if (this.options.sourceMap) {
escodegenParams.sourceMap = 'sourceMap';
escodegenParams.sourceContent = sourceCode;
}
if (this.options.mangle) {
astTree = esmangle.mangle(astTree);
}
const generatorOutput: IGeneratorOutput = escodegen.generate(astTree, {
...escodegenParams,
format: {
compact: this.options.compact
}
});
generatorOutput.map = generatorOutput.map ? generatorOutput.map.toString() : '';
return generatorOutput;
}
.map(function (method) {
return {
name: method.key.name,
body: escodegen.generate(method.value.body)
};
});
}
const generateCode = (ast) => {
const astWithComments = escodegen.attachComments(
ast,
ast.comments,
ast.tokens
);
return escodegen.generate(
astWithComments,
{
comment: true,
format: { index: { style: ' ' } },
}
);
};
private generateCode (sourceCode: string, astTree: ESTree.Program): IGeneratorOutput {
const escodegenParams: escodegen.GenerateOptions = {
...JavaScriptObfuscator.escodegenParams
};
if (this.options.sourceMap) {
escodegenParams.sourceMap = this.options.inputFileName || 'sourceMap';
escodegenParams.sourceContent = sourceCode;
}
const generatorOutput: IGeneratorOutput = escodegen.generate(astTree, {
...escodegenParams,
format: {
compact: this.options.compact
}
});
generatorOutput.map = generatorOutput.map ? generatorOutput.map.toString() : '';
return generatorOutput;
}
function Tree(source, escodegenOptions, acornOptions) {
this.acornOptionDefaults = _.extend({}, acornOptionDefaults, acornOptions);
this.comments = [];
this.tokens = [];
this.acornOptionDefaults.onComment = this.comments;
this.acornOptionDefaults.onToken = this.tokens;
this.tree = acorn.parse(source.toString(), this.acornOptionDefaults);
this.tree = escodegen.attachComments(this.tree, this.comments, this.tokens);
this.body = new Body(this.tree.body, this.acornOptionDefaults);
this.escodegenOptions = _.extend({}, escodegenOptionDefaults, escodegenOptions);
}