-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrollup-plugin-inline-macros.js
564 lines (497 loc) · 27.4 KB
/
rollup-plugin-inline-macros.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
import {createFilter} from '@rollup/pluginutils';
import {basename, join, relative, sep, resolve, dirname} from 'node:path';
import {format} from 'node:util';
import {writeFileSync, readFileSync, readdirSync} from 'node:fs';
const MARKER_COMMENT = '//@inline';
const MACRO_DEFINITION_REGEX = /^\s*(?:export )?const ([^ ]+?)\s*=\s\(?([^)]*?)\)?\s*=>\s*([^;]*);?\s*?\/\/@inline(?:(-global)(:[\S]*)?)?/;
const VALID_DEPENDENCY_NAME_REGEX = /^[a-z_$][a-z0-9_$]*$/i;
const DEFAULT_INCLUDED_FILENAMES_REGEX = /\.(?:js|mjs)$/i;
const LOGGED_PLUGIN_NAME = 'Rollup inline-macros plugin';
const FLAG_GLOBAL = '-global';
const DEBUG = false;
const getParamPlaceholderForIndex = (index) => `%~%>${index}<%~%`; // regex-safe + unlikely to exist anywhere inside macro code
const getParamPlaceholderReplacementRegexForIndex = (index) => new RegExp(getParamPlaceholderForIndex(index), 'g');
const isValidDependencyName = s => s && VALID_DEPENDENCY_NAME_REGEX.test(s);
/**
* A rollup plugin that scans each file for const arrow functions marked with a trailing '//@inline' comment.
* Invocations of those functions within the same file are then replaced with the actual arrow-function code,
* much like early Pascal "inline" functions or macros in other languages.
* Helpful to keep sources DRY while boosting performance in hot execution paths by saving some function calls.
*
* Example:
* const _isLowercaseString = (s) => typeof s === 'string' && s.toLowerCase() === s; //@inline
*
* Invocations like following:
* if (_isLowercaseString(foo)) {
* will be expanded to:
* if ((typeof foo === 'string' && foo.toLowerCase() === foo)) {
*
*
* Current limitations:
* - multiline-expressions MUST NOT contain line-comments (except the initial inline-marker comment)
* - the invocation must match the number of formal parameters (optional parameters MUST be passed explicitly as undefined)
* - invocation parameters that are no identifiers (e.g. object literals or strings) MUST NOT contain commas
*
* @param {RollupInlineMacrosPluginOptions} opts
*
* Author: Lennart Pegel - https://github.com/justlep
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
*/
export default function createRollupInlineMacrosPlugin(opts = {}) {
// Using Rollup's recommended include/exclude filter mechanism -> https://rollupjs.org/guide/en/#example-transformer
const canProcess = createFilter(opts.include || DEFAULT_INCLUDED_FILENAMES_REGEX, opts.exclude);
const logFilePath = opts.logFile && join(__dirname, opts.logFile);
let totalMacros = 0,
totalReplacements = 0,
totalChangedFiles = 0,
totalErrors = 0;
/**
* A set of all line references that belong to macro definitions.
* (may contain multiple entries per single macro in case of multi-line expression macros)
* @type {Set<RollupInlineMacrosPlugin_LineReference>}
*/
const allMacroDefinitionLineReferences = new Set();
/** @type {Map<string, RollupInlineMacrosPlugin_InlineMacro>} */
const globalMacrosByName = new Map();
/** @type {Map<string, RollupInlineMacrosPlugin_InlineMacro[]>} */
const localMacrosByFileId = new Map();
/** @type {Map<string, string[]>|null} */
const logEntriesByFileId = logFilePath ? new Map() : null;
/**
* @param {string} id - the file id in Rollup speak (i.e. the file path)
* @param {string} code
* @param {boolean} logFilePathOnce
* @return {RollupInlineMacrosPlugin_FileUtils}
*/
const getFileUtils = (id, code, logFilePathOnce) => {
let filename = basename(id),
relativeFilePath = (sep === '\\') ? relative(__dirname, id).replace(/\\/g, '/') : relative(__dirname, id),
filePathToLogOnce = logFilePathOnce ? `\n------- ${relativeFilePath} --------\n\n` : '',
logEntriesForFile = logEntriesByFileId ? logEntriesByFileId.get(id) : null,
localMacros = localMacrosByFileId.get(id),
lines = code.split('\n'),
LOG = (lineIndex, msg, ...args) => {
let line = filePathToLogOnce + format(`[${filename}:${lineIndex + 1}]\n${msg}`, ...args);
if (logEntriesForFile) {
logEntriesForFile.push(line);
}
if (opts.verbose) {
console.log('\n' + line);
}
filePathToLogOnce = '';
},
LOG_FORCE = (lineIndex, msg, ...args) => {
let _wasVerbose = opts.verbose;
opts.verbose = true;
LOG(lineIndex, msg, ...args);
opts.verbose = _wasVerbose;
},
_importsHelper;
if (logEntriesForFile === undefined) {
logEntriesByFileId.set(id, logEntriesForFile = []);
}
if (!localMacros) {
localMacrosByFileId.set(id, localMacros = []);
}
return {
filename,
relativeFilePath,
getLineReference: lineIndex => `${relativeFilePath}:${lineIndex + 1}`,
localMacros,
lines,
LOG,
LOG_FORCE,
getImportsHelper: () => _importsHelper || (_importsHelper = new ImportsHelper(relativeFilePath, lines, logEntriesForFile))
};
};
/**
* Phase 1: load each file, parse macro definitions + keep references to the lines they're found in
* @param {string} id - the file path
*/
const scanFile = (id) => {
// console.log('[SCAN] ' + id);
const code = readFileSync(id).toString('utf-8');
const {localMacros, lines, LOG, LOG_FORCE, getLineReference, relativeFilePath, filename} = getFileUtils(id, code, true);
// (1) find arrow functions marked as macro
for (let lineIndex = 0, len = lines.length, line, match; lineIndex < len; lineIndex++) {
line = lines[lineIndex];
let lineReference = getLineReference(lineIndex);
if (!(match = ~line.indexOf(MARKER_COMMENT) && line.match(MACRO_DEFINITION_REGEX))) {
continue;
}
let [, name, paramsString, body, flag, dependenciesSuffix] = match,
trimmedBody = body.trim(),
isMultilineExpression = !trimmedBody,
isGlobal = flag === FLAG_GLOBAL,
hasFunctionBody = trimmedBody === '{',
skipLines = 0,
error,
/** @type {?string[]} */
dependencies = null;
if (hasFunctionBody) {
error = `Non-single-expression function bodies are not yet supported ("${name}")`;
} else if (globalMacrosByName.has(name)) {
error = isGlobal ? `Duplicate name for global macro "${name}"`
: `Ambiguous name for local macro "${name}" (name already used by global macro)`;
}
if (dependenciesSuffix) {
dependencies = dependenciesSuffix.substr(1).split(',').map(s => s.trim());
if (!dependencies.every(isValidDependencyName)) {
error = `Invalid dependency list for macro "${name}: "${dependenciesSuffix}"`;
console.warn(dependencies);
}
}
if (error) {
LOG_FORCE(lineIndex, '(!) ERROR: ' + error);
totalErrors++;
continue;
}
if (isMultilineExpression) {
// Expressions that span over multiple lines will be trimmed line-wise & concatenated
// - An empty'ish or comment line is considered the end of the macro
// - Since we're not parsing code here, trailing '// comments' will break the expression!
for (let lookaheadLineIndex = lineIndex + 1; lookaheadLineIndex < len; lookaheadLineIndex++) {
let _trimmedLine = lines[lookaheadLineIndex].trim();
// keep a reference to all lines of the macro (incl the end marker line),
// so these lines can be skipped in phase 2 for replacements
allMacroDefinitionLineReferences.add(getLineReference(lookaheadLineIndex));
if (!_trimmedLine || /^\s*\/[/*]/.test(_trimmedLine)) {
skipLines = (lookaheadLineIndex - lineIndex);
break;
}
trimmedBody += ' ' + _trimmedLine.replace(/;\s*$/, '');
}
}
allMacroDefinitionLineReferences.add(lineReference);
let invocationRegex = new RegExp(`([^a-zA-Z._~$])${name}\\(([^)]*?)\\)`, 'g'), // groups = prefixChar, paramsString
params = paramsString.replace(/\s/g,'').split(','),
bodyWithPlaceholders = !params.length ? trimmedBody : params.reduce((body, paramName, i) => {
let paramRegex = new RegExp(`([^a-zA-Z._~$])${paramName}([^a-zA-Z_~$])`, 'g');
return body.replace(paramRegex, (m, prefix, suffix) => `${prefix}${getParamPlaceholderForIndex(i)}${suffix}`);
}, `(${trimmedBody})`);
/** @type {RollupInlineMacrosPlugin_InlineMacro} */
let macro = {
name,
params,
body: trimmedBody,
bodyWithPlaceholders,
invocationRegex,
replacementsCount: 0,
lineReference,
relativeFilePath,
filename,
dependencies,
isGlobal
};
if (isGlobal) {
globalMacrosByName.set(name, macro);
} else {
localMacros.push(macro);
}
LOG(lineIndex, `Found ${isGlobal ? 'global' : 'local'} macro: "${macro.name}"` +
(isMultilineExpression ? ' (MULTI-LINE-EXPRESSION)' : '') +
(dependencies ? `\nDependencies (to auto-import): ${dependencies.join(', ')}` : ''));
totalMacros++;
lineIndex += skipLines; // non-zero if we had multiline-expressions
}
};
return {
name: 'inline-macros',
buildStart(inputOpts) {
if (logFilePath) {
// write log file header
let versionInfo = opts.versionName ? `\nfor ${opts.versionName}\n` : '';
writeFileSync(logFilePath, `\nRunning ${LOGGED_PLUGIN_NAME}${versionInfo}\n`);
}
console.log('Scanning for macros...');
let entryFilePath = resolve('./' + inputOpts.input[0]),
totalScannedFiles = 0,
remainingDirPaths = [dirname(entryFilePath)];
for (let dirPath = remainingDirPaths.shift(), entries; dirPath; dirPath = remainingDirPaths.shift()) {
for (let entry of readdirSync(dirPath, {withFileTypes: true})) {
let entryPath = join(dirPath, entry.name);
if (entry.isFile() && canProcess(entryPath)) {
scanFile(entryPath);
totalScannedFiles++;
} else if (entry.isDirectory()) {
remainingDirPaths.push(entryPath);
}
}
}
console.log(` => ${totalScannedFiles} files scanned\n` +
` => ${totalMacros} macros found (${globalMacrosByName.size} global)`);
},
buildEnd(err) {
let hasUnusedMacros = false;
/**
* @param {RollupInlineMacrosPlugin_InlineMacro} macro
* @return {string}
*/
const toMacroUsageString = macro => {
let count = macro.replacementsCount;
hasUnusedMacros = hasUnusedMacros || !count;
return ` ${count ? `${count}x` : '(!) UNUSED '} ${macro.name} - [${macro.lineReference}]`;
};
let usageSummary = [
'Global macros inlining summary:',
...Array.from(globalMacrosByName.values()).map(toMacroUsageString),
'',
'Local macros inlining summary:',
...Array.from(localMacrosByFileId.keys())
.sort()
.map(fileId => localMacrosByFileId.get(fileId))
.filter(macros => macros.length)
.map(macros => macros.map(toMacroUsageString).join('\n')),
''
].join('\n');
let summaryLine1 = `${LOGGED_PLUGIN_NAME} finished ${totalErrors ? `with ${totalErrors} ERROR${totalErrors === 1 ? '' : 'S'}` : 'successfully'}`,
summaryLine2 = `Inlined ${totalReplacements} usages of ${totalMacros} macros (${globalMacrosByName.size} global) in ${totalChangedFiles} files`,
unusedWarning = hasUnusedMacros ? 'NOTICE: found macros which never got inlined\n' : '',
hr = '='.repeat(Math.max(summaryLine1.length, summaryLine2.length)),
summary = `\n${usageSummary}\n${hr}\n${summaryLine1}\n${summaryLine2}\n${unusedWarning}${hr}`;
console.log(summary);
if (logFilePath) {
// write log file lines & summary
let logEntriesToWrite = Array.from(logEntriesByFileId.keys()).sort()
.map(fileId => logEntriesByFileId.get(fileId))
.filter(arr => arr.length)
.map(arr => arr.join('\n\n'));
logEntriesToWrite.push(summary);
if (err) {
logEntriesToWrite.push(err.toString());
}
writeFileSync(logFilePath, logEntriesToWrite.join('\n\n') + '\n', {flag: 'a'});
console.log(`Logs for ${LOGGED_PLUGIN_NAME} written to:\n${logFilePath}\n`);
}
if (totalErrors && !opts.ignoreErrors) {
throw new Error(`${LOGGED_PLUGIN_NAME} throws due to inlining error(s) and 'ignoreErrors' disabled.`);
}
},
/**
* Phase 2: within each file, find invocations of local+global macros and replace invocation with macro body expression
* @param {string} code - the file content returned from phase 1
* @param {string} id - the file path
*/
transform(code, id) {
if (!canProcess(id)) {
return;
}
// console.log('[TRANSFORM] ' + id);
let totalReplacementsBefore = totalReplacements;
const fileUtils = getFileUtils(id, code, false);
const {localMacros, getLineReference, LOG, lines, relativeFilePath} = fileUtils;
/** @type {RollupInlineMacrosPlugin_InlineMacro[]} */
const availableMacros = [...localMacros, ...globalMacrosByName.values()];
/** @type {string[]} */
let originalLines;
lines.forEach((line, lineIndex) => {
let lineReference = getLineReference(lineIndex),
isMacroDefinitionLine = allMacroDefinitionLineReferences.has(lineReference);
if (isMacroDefinitionLine) {
// don't expand macro invocations within macro definitions,
// instead re-process regular invocation lines until no more macro invocations are left
return;
}
for (let shouldScanForInvocations = true, lineIteration = 1; shouldScanForInvocations; lineIteration++) {
shouldScanForInvocations = false;
for (let macro of availableMacros) {
let {name, params, invocationRegex, bodyWithPlaceholders} = macro,
isPossibleInvocationLine = ~line.indexOf(name + '(');
if (!isPossibleInvocationLine) {
continue;
}
let changedLine = line.replace(invocationRegex, (matchedInvocation, invPrefixChar, invParamsString) => {
// FIXME invocations like foo("hey,foo") won't work, but that's ok for now
let invParams = invParamsString.split(',').map(s => s.trim());
// LOG(lineIndex, `Checking invocation of '${name}'`);
if (invParams.length !== params.length) {
LOG(lineIndex, `[ERROR] Mismatch # formal parameters (${params.length}) <> invocation (${invParams.length}): \n -> macro: ${name}\n -> usage: ${line}\n`);
totalErrors++;
return matchedInvocation;
}
let replacedInvocation = invPrefixChar + bodyWithPlaceholders;
invParams.forEach((paramName, i) => {
let placeholderRegex = getParamPlaceholderReplacementRegexForIndex(i);
replacedInvocation = replacedInvocation.replace(placeholderRegex, paramName);
});
return replacedInvocation;
});
if (changedLine !== line) {
if (!originalLines) {
originalLines = lines.slice(); // lazy-copy original lines before any changes
}
let iterationLogString = lineIteration > 1 ? ` [iteration #${lineIteration}]` : '';
LOG(lineIndex, `Inlined: "${name}"${iterationLogString}${macro.isGlobal ? ' (global macro)' : ''}\n`+
`OLD: ${originalLines[lineIndex].trim()}\n`+
`NEW: ${changedLine.trim()}`);
line = changedLine;
lines[lineIndex] = changedLine;
macro.replacementsCount++;
totalReplacements++;
if (macro.relativeFilePath !== relativeFilePath && macro.dependencies) {
// If a (global) macro is used/invoked in a different file than where it was defined,
// it may require importing some additional dependencies from its origin files,
// listed behind the macro-marker, e.g. //@inline-global:_localDoThis,_localDoThat
// console.warn(`! usage of global macro "${macro.name}" outside its definition file \n` +
// ` -> defined in: ${relativeFilePath}\n -> used in: ${macro.relativeFilePath}`);
for (let dependency of macro.dependencies) {
fileUtils.getImportsHelper().addImportIfNotExists(macro.name, macro.filename, dependency, lineIndex);
}
}
// re-iterate, because macros may be using other macros
shouldScanForInvocations = true;
}
}
}
});
if (totalReplacements > totalReplacementsBefore) {
totalChangedFiles++;
}
return {code: lines.join('\n'), map: null};
}
}
}
const IMPORT_FROM_REGEX = / from '[./a-z0-9_$]+?([.a-z0-9_$]+?)(?:\.js)?';?/i;
/**
* Helper for adding additional imports for a macro's dependencies into the respective file where the
* invocation gets inlined.
* (!) Assumptions & limitations:
* - the macro symbol itself is imported in the target file
* - neither the macro nor its dependencies are default exports
* - macro-dependencies are exported by the same file as the macro
* - comments in/after line(s) of an import statement must not contain a macro or dependency name in such a way
* that could be misinterpreted as part of the import, e.g. import {foo} from 'module'; // dont use {foo} here
* - multi-line imports must use trailing commas, not commas at the start of each further module line
*/
class ImportsHelper {
/**
* @param {string} relativePath - the target file in which we want to temper with existing imports
* @param {string[]} lines - the code lines of the target file (NOT a copy!)
* @param {string[]} [logEntries]
*/
constructor(relativePath, lines, logEntries) {
this._filename = basename(relativePath);
this._relativePath = relativePath;
this._lines = lines;
this._addedImports = {};
this._lastImportLine = -1;
this._firstImportLine = lines.length;
this._helperName = `ImportsHelper[${this._filename}]`;
this._addToLog = logEntries ? s => logEntries.push(s) : () => null;
for (let i = lines.length - 1, line; i >= 0; i--) {
line = lines[i];
if (this._lastImportLine < 0 && IMPORT_FROM_REGEX.test(line)) {
this._lastImportLine = i;
}
if (this._lastImportLine >= 0 && line.startsWith('import ')) {
this._firstImportLine = i;
}
}
DEBUG && this._addToLog(`New ${this._helperName} (has imports in line ${this._firstImportLine}-${this._lastImportLine})`);
}
/**
* @param {string} name
* @return {RegExp}
* @private
*/
_createImportedNameRegex(name) {
return new RegExp(`([{,\\s])(${name.replace(/[$\\]/g, '\\$1')})([,}\\s])`, 'i');
}
/**
* @param {string} causingName - the name of the already-imported module we want to add another dependency-import for
* (!) the dependency is assumed to be located in the same file as the causing name
* @param {string} causeFilename
* @param {string} nameToAdd - the name to be imported alongside (and from the same file as) causingName
* @param {number} forLineIndex - the line index of the causing invocation
*/
addImportIfNotExists(causingName, causeFilename, nameToAdd, forLineIndex) {
let causeModuleName = causeFilename.replace(/^.*\/|\.js$/g, ''),
cacheKey = nameToAdd + '@' + causeFilename,
success = false;
const SIMILAR_IMPORT = `{${nameToAdd}} from '${causeModuleName}'`;
DEBUG && this._addToLog(`Trying to auto-add macro-dependency import similar to:\n import ${SIMILAR_IMPORT}`);
if (this._addedImports[cacheKey]) {
this._addToLog(`Skipped adding dependency import - some import like ${SIMILAR_IMPORT} already exists in ${this._filename}`);
return;
}
if (this._firstImportLine > this._lastImportLine) {
throw new Error('Error: no imports in file! ImportsHelper can only alter existing imports.');
}
const _causingNameRegex = this._createImportedNameRegex(causingName);
const _nameToAddRegex = this._createImportedNameRegex(nameToAdd);
DEBUG && this._addToLog(`_causingNameRegex: ${_causingNameRegex}\n`+
`_nameToAddRegex : ${_nameToAddRegex}`);
for (let i = this._lastImportLine, foundModuleName = null, line; i >= this._firstImportLine; i--) {
line = this._lines[i];
if (foundModuleName !== causeModuleName) {
foundModuleName = IMPORT_FROM_REGEX.test(line) && RegExp.$1;
if (foundModuleName !== causeModuleName) {
continue;
}
DEBUG && this._addToLog(`Located imports from "${foundModuleName}" in line ${i}`);
}
if (_nameToAddRegex.test(line)) {
this._addToLog(`Skipped adding macro-dependency ${nameToAdd} (already imported)`);
success = true;
} else if (_causingNameRegex.test(line)) {
let oldLine = line,
replacement = `${RegExp.$1}${RegExp.$2}, ${nameToAdd}${RegExp.$3}`,
newLine = line.replace(_causingNameRegex, replacement);
this._lines[i] = newLine;
this._addToLog(`[${this._filename}:${i+1}]\nAdded dependency-import "${nameToAdd}" for macro "${causingName}"\n` +
`OLD: ${oldLine}\nNEW: ${newLine}`);
success = true;
}
if (success) {
this._addedImports[cacheKey] = true;
} else if (line.startsWith('import ')) {
break;
}
}
if (!success) {
throw new Error(`Failed to auto-add macro-dependency "${nameToAdd}" for macro "${causingName}" into ${this._relativePath}\n`+
`Should have looked similar to: import ${SIMILAR_IMPORT}`);
}
}
}
/**
* @typedef {Object} RollupInlineMacrosPluginOptions
* @property {boolean} verbose - if true, detailed processing info* will be written to the console
* (* = the details otherwise written to the optional logfile only)
* @property {?string} [logFile] - path to a log file (will be overwritten during each run)
* @property {?string} [versionName] - a version name used to be used in the log file (if enabled)
* @property {RegExp} [include] - included filenames pattern (falsy value will default to {@link DEFAULT_INCLUDED_FILENAMES_REGEX})
* @property {RegExp} [exclude] - excluded filenames pattern
* @property {boolean} [ignoreErrors] - set true to make the plugin NOT throw/break the build if errors were detected during processing
*/
/**
* @typedef {Object} RollupInlineMacrosPlugin_InlineMacro
* @property {string} name - the function name
* @property {string[]} params - names of the formal parameters in the function definition
* @property {string} body - the function body code
* @property {string} bodyWithPlaceholders - the function body with formal parameters replaced with placeholders,
* e.g. `(foo,bar) => alert(foo + bar)` will have bodyWithPlaceholders `(alert(%0% + %1%))`
* @property {RegExp} invocationRegex - the regex to match an invocation
* @property {number} replacementsCount
* @property {string} lineReference
* @property {string} relativeFilePath - relative path of the file this macro is defined in
* @property {string} filename - the filename this macro is defined in
* @property {?string[]} dependencies - if the macro is global, this is a list of dependencies which need to be added as imports
* when inlining an invocation within a file which is not the macro's own file
* @property {boolean} isGlobal
*/
/**
* A string containing a filename and line for referencing a code line, e.g. "src/path/file.js:123"
* @typedef {string} RollupInlineMacrosPlugin_LineReference
*/
/**
* @typedef {Object} RollupInlineMacrosPlugin_FileUtils
* @property {string} filename
* @property {string} relativeFilePath
* @property {function(number):string} getLineReference
* @property {RollupInlineMacrosPlugin_InlineMacro[]} localMacros
* @property {string[]} lines
* @property {function} LOG
* @property {function} LOG_FORCE
* @property {function:ImportsHelper} getImportsHelper
*/