-
Notifications
You must be signed in to change notification settings - Fork 1
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 support to string in includes #1
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,19 +154,19 @@ const builtIns = { | |
|
||
concat: new AbstractFunction(), | ||
endsWith: new AbstractFunction(), | ||
includes: new AbstractFunction(), | ||
includes: new GenericFunction({ type: NODE_BUILTIN_METHOD_IMPL, targetClass: 'String', name: 'includes' }, [{ name: 'searchElement' }, { name: 'fromIndex' }]), | ||
indexOf: new AbstractFunction(), | ||
lastIndexOf: new AbstractFunction(), | ||
localeCompare: new AbstractFunction(), | ||
match: new AbstractFunction(), | ||
matchAll: new AbstractFunction(), | ||
match: new GenericFunction({ type: NODE_BUILTIN_METHOD_IMPL, targetClass: 'String', name: 'match' }, [{ name: 'pattern' }]), | ||
matchAll: new GenericFunction({ type: NODE_BUILTIN_METHOD_IMPL, targetClass: 'String', name: 'matchAll' }, [{ name: 'pattern' }]), | ||
normalize: new AbstractFunction(), | ||
padEnd: new AbstractFunction(), | ||
padStart: new AbstractFunction(), | ||
repeat: new AbstractFunction(), | ||
replace: new AbstractFunction(), | ||
replaceAll: new AbstractFunction(), | ||
search: new AbstractFunction(), | ||
replace: new GenericFunction({ type: NODE_BUILTIN_METHOD_IMPL, targetClass: 'String', name: 'replace' }, [{ name: 'searchValue' }, { name: 'newValue' }]), | ||
replaceAll: new GenericFunction({ type: NODE_BUILTIN_METHOD_IMPL, targetClass: 'String', name: 'replaceAll' }, [{ name: 'searchValue' }, { name: 'newValue' }]), | ||
search: new GenericFunction({ type: NODE_BUILTIN_METHOD_IMPL, targetClass: 'String', name: 'search' }, [{ name: 'pattern' }]), | ||
slice: new AbstractFunction(), | ||
split: new AbstractFunction(), | ||
startsWith: new AbstractFunction(), | ||
|
@@ -318,6 +318,43 @@ const builtInsImpls = { | |
valueOf: (target, context, options, runState) => { | ||
return target.valueOf(); | ||
}, | ||
includes: (target, context, options, runState) => { | ||
const elem = context.get('searchElement'); | ||
const from = context.get('fromIndex'); | ||
return target.includes(elem, from); | ||
}, | ||
match: (target, context, options, runState) => { | ||
const pattern = context.get('pattern'); | ||
return target.match(pattern); | ||
}, | ||
matchAll: (target, context, options, runState) => { | ||
const pattern = context.get('pattern'); | ||
return target.match(pattern); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please call |
||
}, | ||
replace: (target, context, options, runState) => { | ||
const searchValue = context.get('searchValue'); | ||
const newValue = context.get('newValue'); | ||
return target.replace( | ||
searchValue, | ||
newValue instanceof AbstractFunction ? | ||
(x) => newValue.exec(x, context, options, runState) : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
newValue | ||
) | ||
}, | ||
replaceAll: (target, context, options, runState) => { | ||
const searchValue = context.get('searchValue'); | ||
const newValue = context.get('newValue'); | ||
return target.replaceAll( | ||
searchValue, | ||
newValue instanceof AbstractFunction ? | ||
(x) => newValue.exec(x, context, options, runState) : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
newValue | ||
); | ||
}, | ||
search: (target, context, options, runState) => { | ||
const pattern = context.get('pattern'); | ||
return target.search(pattern); | ||
}, | ||
}, | ||
JSON: { | ||
parse: (target, context, options, runState) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove
TYPE_OBJECT
fromtypeNames
since it would be an error if a node of typeNODE_LITERAL
has an object as value.