Skip to content

Commit

Permalink
Update transform_files.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Oct 31, 2022
1 parent 9b7f6f9 commit 322c271
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions scripts/transform_files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function parseClassBase(raw, find) {
};
}

function findClass(raw) {
function parseClass(raw) {
return parseClassBase(raw, (nodeType, node) => {
return (
nodeType === 'CallExpression' &&
Expand All @@ -148,13 +148,14 @@ function findClass(raw) {
});
}

function findMixin(raw) {
const keyWord = getVariableNameOfNS(raw, 'fabric.util.object.extend');
const regex = new RegExp(
`${keyWord.replaceAll('.', '\\.')}\\((.+)\\.prototype,\.*\\{`,
'gm'
);
return parseClassBase(raw, regex);
function parseMixin(raw) {
'fabric.util.object.extend';
return parseClassBase(raw, (nodeType, node) => {
return (
nodeType === 'CallExpression' &&
printASTNode(raw, node.callee).replaceAll('(', '').endsWith('createClass')
);
});
}

function transformSuperCall(raw) {
Expand Down Expand Up @@ -253,7 +254,7 @@ function transformClass(type, raw, options = {}) {
properties,
defaultValues,
declaration,
} = type === 'mixin' ? findMixin(raw) : findClass(raw);
} = type === 'mixin' ? parseMixin(raw) : parseClass(raw);
let body = rawBody;
let offset = start;
const staticCandidates = [];
Expand Down

0 comments on commit 322c271

Please sign in to comment.