Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add sutiable RegExp prototype methods #4737

Merged
merged 1 commit into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/ast/values.ts
Expand Up @@ -200,6 +200,14 @@ const literalNumberMembers: MemberDescriptions = assembleMemberDescriptions(
objectMembers
);

const literalRegExpMembers: MemberDescriptions = assembleMemberDescriptions(
{
exec: returnsUnknown,
test: returnsBoolean
},
objectMembers
);

export const literalStringMembers: MemberDescriptions = assembleMemberDescriptions(
{
anchor: returnsString,
Expand Down Expand Up @@ -258,6 +266,9 @@ export const literalStringMembers: MemberDescriptions = assembleMemberDescriptio
export function getLiteralMembersForValue<T extends LiteralValue = LiteralValue>(
value: T
): MemberDescriptions {
if (value instanceof RegExp) {
return literalRegExpMembers;
}
switch (typeof value) {
case 'boolean': {
return literalBooleanMembers;
Expand Down
4 changes: 4 additions & 0 deletions test/form/samples/builtin-prototypes/literal/main.js
Expand Up @@ -48,6 +48,10 @@ const _numberHasOwnProperty = (1).hasOwnProperty('toString').valueOf();
const _numberIsPrototypeOf = (1).isPrototypeOf(1).valueOf();
const _numberPropertyIsEnumerable = (1).propertyIsEnumerable('toString').valueOf();

// RegExp prototype
/1/.test(2);
/1/.exec(1);

// string prototype
'ab'.valueOf();
'ab'.valueOf().valueOf();
Expand Down