Skip to content

Commit

Permalink
Fix checking of alloy builtin usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanharris committed Oct 12, 2023
1 parent 70e69c6 commit 5ef5536
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions Alloy/commands/compile/ast/builtins-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,33 @@ module.exports = class BuiltIns extends Visitor {
constructor(opts) {
super();
this.opts = opts;
this.regex = /^(\/?alloy)\/(.+)$/;

}
visitCallExpression(n) {
const string = n.arguments[0];
let match;
if (
isRequire(n) &&
string.expression.type === 'StringLiteral' &&
string.expression.value.startsWith('/alloy')
(match = string.expression.value.match(this.regex)) !== null
) {
const match = string.expression.value.match(/^(\/?alloy)\/(.+)$/);

if (match) {
if (!EXCLUDE.includes(match[2]) && !loaded.includes(match[2])) {
// Make sure it hasn't already been copied to Resources
var name = appendExtension(match[2], 'js');
if (fs.existsSync(path.join(this.opts.dir.resources, match[1], name))) {
return super.visitCallExpression(n);
}
if (!EXCLUDE.includes(match[2]) && !loaded.includes(match[2])) {
// Make sure it hasn't already been copied to Resources
var name = appendExtension(match[2], 'js');
if (fs.existsSync(path.join(this.opts.dir.resources, match[1], name))) {
return super.visitCallExpression(n);
}

// make sure the builtin exists
var source = path.join(BUILTINS_PATH, name);
var dest = path.join(this.opts.dir.resources, 'alloy', name);
loadBuiltin(source, name, dest);
// make sure the builtin exists
var source = path.join(BUILTINS_PATH, name);
var dest = path.join(this.opts.dir.resources, 'alloy', name);
loadBuiltin(source, name, dest);

if ('moment.js' === name) {
// if momentjs is required in the project, also load the
// localizations which may be used
loadMomentLanguages(this.opts);
}
if ('moment.js' === name) {
// if momentjs is required in the project, also load the
// localizations which may be used
loadMomentLanguages(this.opts);
}
}
}
Expand Down

0 comments on commit 5ef5536

Please sign in to comment.