Skip to content

Commit

Permalink
Merge branch 'master' into ci
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Dec 22, 2021
2 parents 9dde7e7 + 48f0e31 commit f0a1fd3
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*.js eol=lf
* text=auto eol=lf
2 changes: 0 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ jobs:
node: ['10', '12', '14', '16', '17']
name: Node ${{ matrix.node }} (Windows)
steps:
- name: Configure git line-breaks
run: git config --global core.autocrlf false
- name: Checkout Commit
uses: actions/checkout@v2
- name: Setup Node
Expand Down
1 change: 1 addition & 0 deletions docs/05-plugin-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ type ModuleInfo = {
ast: ESTree.Program; // the parsed abstract syntax tree if available
isEntry: boolean; // is this a user- or plugin-defined entry point
isExternal: boolean; // for external modules that are referenced but not included in the graph
isIncluded: boolean | null; // is the module included after tree-shaking, `null` if external or not yet available
importedIds: string[]; // the module ids statically imported by this module
importers: string[]; // the ids of all modules that statically import this module
dynamicallyImportedIds: string[]; // the module ids imported by this module via dynamic import()
Expand Down
5 changes: 4 additions & 1 deletion rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ const nodePlugins = [
json(),
conditionalFsEventsImport(),
string({ include: '**/*.md' }),
commonjs({ include: 'node_modules/**' }),
commonjs({
ignoreTryCatch: false,
include: 'node_modules/**'
}),
typescript()
];

Expand Down
1 change: 1 addition & 0 deletions src/ExternalModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default class ExternalModule {
},
isEntry: false,
isExternal: true,
isIncluded: null,
meta,
syntheticNamedExports: false
};
Expand Down
7 changes: 7 additions & 0 deletions src/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
TransformModuleJSON
} from './rollup/types';
import { EMPTY_OBJECT } from './utils/blank';
import { BuildPhase } from './utils/buildPhase';
import {
augmentCodeLocation,
errAmbiguousExternalNamespaces,
Expand Down Expand Up @@ -287,6 +288,12 @@ export default class Module {
},
isEntry,
isExternal: false,
get isIncluded() {
if (module.graph.phase !== BuildPhase.GENERATE) {
return null;
}
return module.isIncluded();
},
meta,
syntheticNamedExports
};
Expand Down
31 changes: 29 additions & 2 deletions src/ast/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,28 @@ const literalNumberMembers: MemberDescriptions = assembleMemberDescriptions(

const literalStringMembers: MemberDescriptions = assembleMemberDescriptions(
{
anchor: returnsString,

at: returnsUnknown,
big: returnsString,
blink: returnsString,
bold: returnsString,
charAt: returnsString,
charCodeAt: returnsNumber,
codePointAt: returnsNumber,
codePointAt: returnsUnknown,
concat: returnsString,
endsWith: returnsBoolean,
fixed: returnsString,
fontcolor: returnsString,
fontsize: returnsString,
includes: returnsBoolean,
indexOf: returnsNumber,
italics: returnsString,
lastIndexOf: returnsNumber,
link: returnsString,
localeCompare: returnsNumber,
match: returnsBoolean,
match: returnsUnknown,
matchAll: returnsUnknown,
normalize: returnsString,
padEnd: returnsString,
padStart: returnsString,
Expand All @@ -183,17 +195,32 @@ const literalStringMembers: MemberDescriptions = assembleMemberDescriptions(
returns: UNKNOWN_LITERAL_STRING
}
},
replaceAll: {
value: {
callsArgs: [1],
returns: UNKNOWN_LITERAL_STRING
}
},
search: returnsNumber,
slice: returnsString,
small: returnsString,
split: returnsUnknown,
startsWith: returnsBoolean,
strike: returnsString,
sub: returnsString,
substr: returnsString,
substring: returnsString,
sup: returnsString,
toLocaleLowerCase: returnsString,
toLocaleUpperCase: returnsString,
toLowerCase: returnsString,
toString: returnsString, // overrides the toString() method of the Object object; it does not inherit Object.prototype.toString()
toUpperCase: returnsString,
trim: returnsString,
trimEnd: returnsString,
trimLeft: returnsString,
trimRight: returnsString,
trimStart: returnsString,
valueOf: returnsString
},
objectMembers
Expand Down
1 change: 1 addition & 0 deletions src/rollup/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ interface ModuleInfo {
importers: readonly string[];
isEntry: boolean;
isExternal: boolean;
isIncluded: boolean | null;
meta: CustomPluginOptions;
syntheticNamedExports: boolean | string;
}
Expand Down
14 changes: 6 additions & 8 deletions src/watch/fsevents-importer.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
let fsEvents: unknown;
let fsEventsImportError: Error | undefined;

export function loadFsEvents(): Promise<void> {
export async function loadFsEvents(): Promise<void> {
const moduleName = 'fsevents';

return import(moduleName)
.then(namespace => {
fsEvents = namespace.default;
})
.catch(err => {
fsEventsImportError = err;
});
try {
({ default: fsEvents } = await import(moduleName));
} catch (err: any) {
fsEventsImportError = err;
}
}

// A call to this function will be injected into the chokidar code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down Expand Up @@ -139,6 +140,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down Expand Up @@ -135,6 +136,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down Expand Up @@ -218,6 +219,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down Expand Up @@ -311,6 +313,7 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down Expand Up @@ -134,6 +135,7 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down
1 change: 1 addition & 0 deletions test/form/samples/builtin-prototypes/literal/_expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ true.valueOf()();
'ab'.charAt(1)();
null.unknown;
'ab'.replace( 'a', () => console.log( 1 ) || 'b' );
'ab'.replaceAll( 'a', () => console.log( 1 ) || 'b' );

// deep property access is forbidden
true.x.y;
Expand Down
31 changes: 28 additions & 3 deletions test/form/samples/builtin-prototypes/literal/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,59 @@ const _numberToLocaleString = (1).toLocaleString().trim();
const _numberToString = (1).toString().trim();

// string prototype
const _at = 'ab'.at( 1 )
const _charAt = 'ab'.charAt( 1 ).trim();
const _charCodeAt = 'ab'.charCodeAt( 1 ).toExponential( 2 );
const _codePointAt = 'ab'.codePointAt( 1 ).toExponential( 2 );
const _codePointAt = 'ab'.codePointAt( 1 );
const _concat = 'ab'.concat( 'c' ).trim();
const _includes = 'ab'.includes( 'a' ).valueOf();
const _endsWith = 'ab'.endsWith( 'a' ).valueOf();
const _indexOf = 'ab'.indexOf( 'a' ).toExponential( 2 );
const _lastIndexOf = 'ab'.lastIndexOf( 'a' ).toExponential( 2 );
const _localeCompare = 'ab'.localeCompare( 'a' ).toExponential( 2 );
const _match = 'ab'.match( /a/ ).valueOf();
const _match = 'ab'.match( /a/ )
const _matchAll = 'ab'.matchAll( /a/ )
const _normalize = 'ab'.normalize().trim();
const _padEnd = 'ab'.padEnd( 4, 'a' ).trim();
const _padStart = 'ab'.padStart( 4, 'a' ).trim();
const _repeat = 'ab'.repeat( 2 ).trim();
const _replace = 'ab'.replace( 'a', () => 'b' ).trim();
const _replaceEffect = 'ab'.replace( 'a', () => console.log( 1 ) || 'b' );
const _replaceAll = 'ab'.replaceAll( 'a', () => 'b' ).trim();
const _replaceAllEffect = 'ab'.replaceAll( 'a', () => console.log( 1 ) || 'b' );
const _search = 'ab'.search( /a/ ).toExponential( 2 );
const _slice = 'ab'.slice( 0, 1 ).trim();
const _split = 'ab'.split( 'a' );
const _startsWith = 'ab'.startsWith( 'a' ).valueOf();
const _substr = 'ab'.substr( 0, 1 ).trim();
const _substring = 'ab'.substring( 0, 1 ).trim();
const _toLocaleLowerCase = 'ab'.toLocaleLowerCase().trim();
const _toLocaleUpperCase = 'ab'.toLocaleUpperCase().trim();
const _toLowerCase = 'ab'.toLowerCase().trim();
const _toString = 'ab'.trim();
const _toUpperCase = 'ab'.toUpperCase().trim();
const _trim = 'ab'.trim().trim();
const _trimEnd = 'ab'.trimEnd().trim();
const _trimStart = 'ab'.trimStart().trim();
const _stringValueOf = 'ab'.valueOf().trim();

// DEPRECATED prototype methods
const _anchor = 'ab'.anchor().trim();
const _big = 'ab'.big().trim();
const _blink = 'ab'.blink().trim();
const _bold = 'ab'.bold().trim();
const _fixed = 'ab'.fixed().trim();
const _fontcolor = 'ab'.fontcolor().trim();
const _fontsize = 'ab'.fontsize().trim();
const _italics = 'ab'.italics().trim();
const _link = 'ab'.link().trim();
const _small = 'ab'.small().trim();
const _strike = 'ab'.strike().trim();
const _sub = 'ab'.sub().trim();
const _substr = 'ab'.substr(0, 1).trim();
const _sup = 'ab'.sup().trim();
const _trimLeft = 'ab'.trimLeft().trim();
const _trimRight = 'ab'.trimRight().trim();

// inherited
const _stringHasOwnProperty = 'ab'.hasOwnProperty( 'toString' ).valueOf();
const _stringIsPrototypeOf = 'ab'.isPrototypeOf( '' ).valueOf();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
},
Expand All @@ -126,6 +127,7 @@ module.exports = {
importers: [getId('main')],
isEntry: false,
isExternal: true,
isIncluded: null,
meta: {},
syntheticNamedExports: false
},
Expand Down Expand Up @@ -155,6 +157,7 @@ module.exports = {
importers: [getId('dynamic'), getId('main')],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
},
Expand Down Expand Up @@ -227,6 +230,7 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
}
Expand Down
4 changes: 4 additions & 0 deletions test/function/samples/manual-chunks-info/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
},
Expand All @@ -125,6 +126,7 @@ module.exports = {
importers: [getId('main')],
isEntry: false,
isExternal: true,
isIncluded: null,
meta: {},
syntheticNamedExports: false
},
Expand Down Expand Up @@ -154,6 +156,7 @@ module.exports = {
importers: [getId('dynamic'), getId('main')],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
},
Expand Down Expand Up @@ -226,6 +229,7 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
}
Expand Down
2 changes: 2 additions & 0 deletions test/function/samples/module-parsed-hook/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: false,
meta: {},
syntheticNamedExports: false
},
Expand Down Expand Up @@ -103,6 +104,7 @@ module.exports = {
importers: [ID_MAIN],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
}
Expand Down

0 comments on commit f0a1fd3

Please sign in to comment.