@@ -74,6 +74,7 @@ module.exports = {
7474meta : {
7575messages : {
7676error : 'Use `const { {{name}} } = primordials;` instead of the global.' ,
77+ errorPolyfill : 'Use `const { {{name}} } = require("internal/util");` instead of the primordial.' ,
7778} ,
7879schema : {
7980type : 'array' ,
@@ -88,6 +89,10 @@ module.exports = {
8889items : { type : 'string' } ,
8990} ,
9091into : { type : 'string' } ,
92+ polyfilled : {
93+ type : 'array' ,
94+ items : { type : 'string' } ,
95+ } ,
9196} ,
9297additionalProperties : false ,
9398} ,
@@ -99,6 +104,7 @@ module.exports = {
99104
100105const nameMap = new Map ( ) ;
101106const renameMap = new Map ( ) ;
107+ const polyfilledSet = new Set ( ) ;
102108
103109for ( const option of context . options ) {
104110const names = option . ignore || [ ] ;
@@ -109,6 +115,11 @@ module.exports = {
109115if ( option . into ) {
110116renameMap . set ( option . name , option . into ) ;
111117}
118+ if ( option . polyfilled ) {
119+ for ( const propertyName of option . polyfilled ) {
120+ polyfilledSet . add ( `${ option . name } ${ propertyName [ 0 ] . toUpperCase ( ) } ${ propertyName . slice ( 1 ) } ` ) ;
121+ }
122+ }
112123}
113124
114125let reported ;
@@ -186,6 +197,17 @@ module.exports = {
186197} ,
187198VariableDeclarator ( node ) {
188199const name = node . init ?. name ;
200+ if ( name === 'primordials' && node . id . type === 'ObjectPattern' ) {
201+ const name = node . id . properties . find ( ( { key } ) => polyfilledSet . has ( key . name ) ) ?. key . name ;
202+ if ( name ) {
203+ context . report ( {
204+ node,
205+ messageId : 'errorPolyfill' ,
206+ data : { name } ,
207+ } ) ;
208+ return ;
209+ }
210+ }
189211if ( name !== undefined && isTarget ( nameMap , name ) &&
190212node . id . type === 'Identifier' &&
191213! globalScope . set . get ( name ) ?. defs . length ) {
0 commit comments