Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const evalLiteral = node => {
assert.strictEqual(node.type, NODE_LITERAL);

const { value } = node;
const typeNames = [TYPE_NUMBER, TYPE_BOOLEAN, TYPE_STRING];
const typeNames = [TYPE_NUMBER, TYPE_BOOLEAN, TYPE_STRING, TYPE_OBJECT];
Comment thread
alisonrag marked this conversation as resolved.
Outdated
assert(value === null || typeNames.includes(typeof value), `Expected one of ${typeNames.map(t => `'${t}'`).join(', ')} or null as argument`);

return value;
Expand Down
49 changes: 43 additions & 6 deletions lib/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
Comment thread
alisonrag marked this conversation as resolved.
Outdated
},
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) :
Comment thread
alisonrag marked this conversation as resolved.
Outdated
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) :
Comment thread
alisonrag marked this conversation as resolved.
Outdated
newValue
);
},
search: (target, context, options, runState) => {
const pattern = context.get('pattern');
return target.search(pattern);
},
},
JSON: {
parse: (target, context, options, runState) => {
Expand Down