Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function parse(text) {
try {
const glimmer = require("@glimmer/syntax").preprocess;
return glimmer(text, {
plugins: {
ast: [removeWhiteSpace]
}
});
/* istanbul ignore next */
} catch (error) {
const matches = error.message.match(/on line (\d+)/);
if (matches) {
throw createError(error.message, {
start: { line: Number(matches[1]), column: 0 }
});
} else {
throw error;
}
}
}
module.exports = function processTemplate(template, opts = {}) {
let newAst = preprocess(
template,
Object.assign(
{},
{
plugins: {
ast: [
function(env) {
return {
name: 'plugin-under-test',
visitors: {
Program: function(node) {
let plugin = new Plugin(env);
plugin.syntax = env.syntax;
return plugin.transform(node);
},
},
export function compile(
hbsCode: string,
options: boolean | { isComponent?: boolean; isModule?: boolean; includeImport?: boolean } = true
): string {
if (typeof options === 'boolean') {
return compile(hbsCode, { isComponent: options })
}
const isComponent = !!options.isComponent
const isModule = !!options.isModule
const includeImport = !!options.includeImport && isModule
const glimmerProgram = preprocess(hbsCode)
const babelProgram: Babel.Program = createProgram(glimmerProgram, isComponent, isModule, includeImport)
return generate(babelProgram).code
}
const uri = params.textDocument.uri;
if (getExtension(params.textDocument) !== '.hbs') {
return [];
}
const project = this.server.projectRoots.projectForUri(uri);
if (!project) {
return [];
}
let document = this.server.documents.get(uri);
let offset = document.offsetAt(params.position);
let originalText = document.getText();
let text = originalText.slice(0, offset) + 'ELSCompletionDummy' + originalText.slice(offset);
let ast = preprocess(text);
let focusPath = ASTPath.toPosition(ast, toPosition(params.position));
if (!focusPath) {
return [];
}
const { root } = project;
let completions: CompletionItem[] = [];
if (isMustachePath(focusPath)) {
completions.push(...listComponents(root));
completions.push(...listHelpers(root));
completions.push(...emberMustacheItems);
} else if (isBlockPath(focusPath)) {
completions.push(...listComponents(root));
completions.push(...emberBlockItems);
} else if (isSubExpressionPath(focusPath)) {
verify(options) {
let messages = [];
let pendingStatus = this.statusForModule('pending', options.moduleId);
let shouldIgnore = this.statusForModule('ignore', options.moduleId);
if (shouldIgnore) {
return messages;
}
let source = stripBom(options.source);
let templateAST;
try {
templateAST = preprocess(source, {
mode: 'codemod',
});
} catch (error) {
let message = buildErrorMessage(options.moduleId, error);
messages.push(message);
}
let rules = this.buildRules({
results: messages,
pending: pendingStatus,
moduleId: options.moduleId,
moduleName: options.moduleId,
rawSource: source,
});
for (let rule of rules) {
process(content: string): SymbolInformation[] {
let ast = preprocess(content);
let symbols: SymbolInformation[] = [];
traverse(ast, {
BlockStatement(node: any) {
if (node.program.blockParams.length === 0) return;
node.program.blockParams.forEach((blockParam: string) => {
let symbol = SymbolInformation.create(blockParam, SymbolKind.Variable, toLSRange(node.loc));
symbols.push(symbol);
});
}
});
return symbols;
}
module.exports = function(fileInfo, api, options) {
const config = new Config(options);
if (shouldSkipFile(fileInfo, config)) {
return fileInfo.source;
}
const ast = glimmer.preprocess(fileInfo.source, {
mode: 'codemod',
parseOptions: { ignoreStandalone: true },
});
const b = glimmer.builders;
/**
* Transform the attributes names & values properly
*/
const transformAttrs = attrs => {
return attrs.map(a => {
let _key = a.key;
let _valueType = a.value.type;
let _value;
if (!isAttribute(a.key)) {
_key = `@${_key}`;
}
let uri = params.textDocument.uri;
let filePath = uriToFilePath(uri);
if (!filePath) {
return null;
}
const project = this.server.projectRoots.projectForPath(filePath);
if (!project) {
return null;
}
let extension = getExtension(params.textDocument);
if (extension === '.hbs') {
let content = this.server.documents.get(uri).getText();
let ast = preprocess(content);
let focusPath = ASTPath.toPosition(ast, toPosition(params.position));
if (!focusPath) {
return null;
}
if (this.isComponentOrHelperName(focusPath)) {
const componentOrHelperName = focusPath.node.original;
const templatePath = path.join(project.root, 'app', 'components', `${componentOrHelperName}.js`);
const componentPath = path.join(project.root, 'app', 'templates', 'components', `${componentOrHelperName}.hbs`);
const helperPath = path.join(project.root, 'app', 'helpers', `${componentOrHelperName}.js`);
return pathsToLocations(templatePath, componentPath, helperPath);
}
} else if (extension === '.js') {
let content = this.server.documents.get(uri).getText();