Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import compileModule from '../../../utils/compileModule';
import pkg from 'ember-template-recast/package.json';
const ID = 'ember-template-recast';
export default {
id: ID,
displayName: ID,
version: pkg.version,
homepage: pkg.homepage || 'https://github.com/ember-template-lint/ember-template-recast',
defaultParserID: 'ember-template-recast',
loadTransformer(callback) {
require(
['../../../transpilers/babel', 'ember-template-recast'],
(transpile, recast) => callback({ transpile: transpile.default, recast }),
);
},
transform({ transpile, recast }, transformCode, code) {
transformCode = transpile(transformCode);
const transformModule = compileModule(transformCode);
// allow "export default" instead of "module.exports = "
const transform = transformModule.__esModule ?
import compileModule from '../../../utils/compileModule';
import pkg from 'ember-template-recast/package.json';
const ID = 'ember-template-recast';
export default {
id: ID,
displayName: ID,
version: pkg.version,
homepage: pkg.homepage || 'https://github.com/ember-template-lint/ember-template-recast',
defaultParserID: 'ember-template-recast',
loadTransformer(callback) {
require(
['../../../transpilers/babel', 'ember-template-recast'],
(transpile, recast) => callback({ transpile: transpile.default, recast }),
);
},
transform({ transpile, recast }, transformCode, code) {
transformCode = transpile(transformCode);
const transformModule = compileModule(transformCode);
// allow "export default" instead of "module.exports = "
let message = buildErrorMessage(options.moduleId, error);
messages.push(message);
}
let rules = this.buildRules({
results: messages,
pending: pendingStatus,
moduleId: options.moduleId,
moduleName: options.moduleId,
configResolver: options.configResolver,
rawSource: source,
});
for (let rule of rules) {
try {
transform(templateAST, () => rule.getVisitor());
} catch (error) {
let message = buildErrorMessage(options.moduleId, error);
messages.push(message);
}
}
if (pendingStatus) {
if (messages.length === 0) {
messages.push({
rule: 'invalid-pending-module',
message: `Pending module (\`${options.moduleId}\`) passes all rules. Please remove \`${options.moduleId}\` from pending list.`,
moduleId: options.moduleId,
severity: 2,
});
} else {
if (pendingStatus.only) {
module.exports = function transform(fileInfo, config, invokableData = {}) {
config = config || {};
config.helpers = config.helpers || [];
config.skipBuiltInComponents =
'skipBuiltInComponents' in config ? config.skipBuiltInComponents : false;
config.skipFilesThatMatchRegex = config.skipFilesThatMatchRegex || null;
if (shouldSkipFile(fileInfo, config)) {
return fileInfo.source;
}
let { code: toAngleBracket } = recast.transform(fileInfo.source, () =>
transformToAngleBracket(fileInfo, config, invokableData)
);
let attrEqualEmptyString = new RegExp(_EMPTY_STRING_, 'gi');
let dataEqualsNoValue = /(data-\S+)=""/gim;
toAngleBracket = toAngleBracket.replace(attrEqualEmptyString, '');
toAngleBracket = toAngleBracket.replace(dataEqualsNoValue, '$1');
return toAngleBracket;
};
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 = parse(source);
} 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,
configResolver: options.configResolver,
rawSource: source,
});
for (let rule of rules) {
try {