| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -243,6 +243,9 @@ rules: | |||
| 243 | 243 | into: Safe | |
| 244 | 244 | - name: String | |
| 245 | 245 | - name: Symbol | |
| 246 | + polyfilled: | ||
| 247 | + - asyncDispose | ||
| 248 | + - dispose | ||
| 246 | 249 | - name: SyntaxError | |
| 247 | 250 | - name: TypeError | |
| 248 | 251 | - name: Uint16Array | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -176,6 +176,22 @@ new RuleTester({ | |||
| 176 | 176 | options: [{ name: 'Symbol' }], | |
| 177 | 177 | errors: [{ message: /const { SymbolIterator } = primordials/ }] | |
| 178 | 178 | }, | |
| 179 | + { | ||
| 180 | + code: ` | ||
| 181 | + const { SymbolAsyncDispose } = primordials; | ||
| 182 | + const a = { [SymbolAsyncDispose] () {} } | ||
| 183 | + `, | ||
| 184 | + options: [{ name: 'Symbol', polyfilled: ['asyncDispose', 'dispose'] }], | ||
| 185 | + errors: [{ message: /const { SymbolAsyncDispose } = require\("internal\/util"\)/ }] | ||
| 186 | + }, | ||
| 187 | + { | ||
| 188 | + code: ` | ||
| 189 | + const { SymbolDispose } = primordials; | ||
| 190 | + const a = { [SymbolDispose] () {} } | ||
| 191 | + `, | ||
| 192 | + options: [{ name: 'Symbol', polyfilled: ['asyncDispose', 'dispose'] }], | ||
| 193 | + errors: [{ message: /const { SymbolDispose } = require\("internal\/util"\)/ }] | ||
| 194 | + }, | ||
| 179 | 195 | { | |
| 180 | 196 | code: ` | |
| 181 | 197 | const { ObjectDefineProperty, Symbol } = primordials; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,6 +74,7 @@ module.exports = { | |||
| 74 | 74 | meta: { | |
| 75 | 75 | messages: { | |
| 76 | 76 | error: 'Use `const { {{name}} } = primordials;` instead of the global.', | |
| 77 | + errorPolyfill: 'Use `const { {{name}} } = require("internal/util");` instead of the primordial.', | ||
| 77 | 78 | }, | |
| 78 | 79 | schema: { | |
| 79 | 80 | type: 'array', | |
@@ -88,6 +89,10 @@ module.exports = { | |||
| 88 | 89 | items: { type: 'string' }, | |
| 89 | 90 | }, | |
| 90 | 91 | into: { type: 'string' }, | |
| 92 | + polyfilled: { | ||
| 93 | + type: 'array', | ||
| 94 | + items: { type: 'string' }, | ||
| 95 | + }, | ||
| 91 | 96 | }, | |
| 92 | 97 | additionalProperties: false, | |
| 93 | 98 | }, | |
@@ -99,6 +104,7 @@ module.exports = { | |||
| 99 | 104 | ||
| 100 | 105 | const nameMap = new Map(); | |
| 101 | 106 | const renameMap = new Map(); | |
| 107 | + const polyfilledSet = new Set(); | ||
| 102 | 108 | ||
| 103 | 109 | for (const option of context.options) { | |
| 104 | 110 | const names = option.ignore || []; | |
@@ -109,6 +115,11 @@ module.exports = { | |||
| 109 | 115 | if (option.into) { | |
| 110 | 116 | renameMap.set(option.name, option.into); | |
| 111 | 117 | } | |
| 118 | + if (option.polyfilled) { | ||
| 119 | + for (const propertyName of option.polyfilled) { | ||
| 120 | + polyfilledSet.add(`${option.name}${propertyName[0].toUpperCase()}${propertyName.slice(1)}`); | ||
| 121 | + } | ||
| 122 | + } | ||
| 112 | 123 | } | |
| 113 | 124 | ||
| 114 | 125 | let reported; | |
@@ -186,6 +197,17 @@ module.exports = { | |||
| 186 | 197 | }, | |
| 187 | 198 | VariableDeclarator(node) { | |
| 188 | 199 | const 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 | + } | ||
| 189 | 211 | if (name !== undefined && isTarget(nameMap, name) && | |
| 190 | 212 | node.id.type === 'Identifier' && | |
| 191 | 213 | !globalScope.set.get(name)?.defs.length) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments