Skip to content

Commit

Permalink
add entries definitions for /promise/
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Nov 4, 2023
1 parent 6f8a0c9 commit 93cd08e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
55 changes: 54 additions & 1 deletion scripts/build-entries/entries-definitions.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { $prototype, $virtual, $static, $patchableStatic, $namespace, $helper, $justImport } from './templates.mjs';
import {
$prototype,
$virtual,
$static,
$staticWithContext,
$patchableStatic,
$namespace,
$helper,
$justImport,
} from './templates.mjs';

export const features = {
'aggregate-error/index': {
Expand Down Expand Up @@ -701,6 +710,50 @@ export const features = {
modules: ['es.object.values'],
template: $static({ namespace: 'Object', method: 'values' }),
},
'promise/index': {
modules: [/^(?:es|esnext)\.promise\./],
template: $namespace({ name: 'Promise' }),
},
'promise/all': {
modules: ['es.promise.constructor', 'es.promise.all'],
template: $staticWithContext({ namespace: 'Promise', method: 'all' }),
},
'promise/all-settled': {
modules: ['es.promise.constructor', 'es.promise.all-settled'],
template: $staticWithContext({ namespace: 'Promise', method: 'allSettled' }),
},
'promise/any': {
modules: ['es.promise.constructor', 'es.promise.any'],
template: $staticWithContext({ namespace: 'Promise', method: 'any' }),
},
'promise/catch': {
modules: ['es.promise.constructor', 'es.promise.catch'],
template: $prototype({ namespace: 'Promise', method: 'catch' }),
},
'promise/virtual/catch': {
modules: ['es.promise.constructor', 'es.promise.catch'],
template: $virtual({ namespace: 'Promise', method: 'catch' }),
},
'promise/finally': {
modules: ['es.promise.constructor', 'es.promise.finally'],
template: $prototype({ namespace: 'Promise', method: 'finally' }),
},
'promise/virtual/finally': {
modules: ['es.promise.constructor', 'es.promise.finally'],
template: $virtual({ namespace: 'Promise', method: 'finally' }),
},
'promise/race': {
modules: ['es.promise.constructor', 'es.promise.race'],
template: $staticWithContext({ namespace: 'Promise', method: 'race' }),
},
'promise/reject': {
modules: ['es.promise.constructor', 'es.promise.reject'],
template: $staticWithContext({ namespace: 'Promise', method: 'reject' }),
},
'promise/resolve': {
modules: ['es.promise.constructor', 'es.promise.resolve'],
template: $staticWithContext({ namespace: 'Promise', method: 'resolve' }),
},
'reflect/index': {
modules: [/^(?:es|esnext)\.reflect\./],
template: $namespace({ name: 'Reflect' }),
Expand Down
18 changes: 8 additions & 10 deletions scripts/build-entries/templates.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,29 @@ export const $static = t(p => dedent`
module.exports = path.${ p.namespace }.${ p.method };
`);

export const $patchableStatic = t(p => dedent`
export const $staticWithContext = t(p => dedent`
${ importModules(p.modules, p.level) }
var getBuiltIn = ${ importInternal('get-built-in', p.level) }
var getBuiltInStaticMethod = ${ importInternal('get-built-in-static-method', p.level) }
var isCallable = ${ importInternal('is-callable', p.level) }
var apply = ${ importInternal('function-apply', p.level) }
var method = getBuiltInStaticMethod('${ p.namespace }', '${ p.method }');
module.exports = function ${ isAllowedFunctionName(p.method) ? p.method : '' }() {
return apply(getBuiltInStaticMethod('${ p.namespace }', '${ p.method }'), this, arguments);
return apply(method, isCallable(this) ? this : getBuiltIn('${ p.namespace }'), arguments);
};
`);

export const $patchableStaticWithContext = t(p => dedent`
export const $patchableStatic = t(p => dedent`
${ importModules(p.modules, p.level) }
var getBuiltIn = ${ importInternal('get-built-in', p.level) }
var getBuiltInStaticMethod = ${ importInternal('get-built-in-static-method', p.level) }
var isCallable = ${ importInternal('is-callable', p.level) }
var apply = ${ importInternal('function-apply', p.level) }
module.exports = function ${ isAllowedFunctionName(p.method) ? p.method : '' }() {
return apply(
getBuiltInStaticMethod('${ p.namespace }', '${ p.method }'),
isCallable(this) ? this : getBuiltIn('${ p.namespace }'),
arguments
);
return apply(getBuiltInStaticMethod('${ p.namespace }', '${ p.method }'), this, arguments);
};
`);

Expand Down

0 comments on commit 93cd08e

Please sign in to comment.