Skip to content

Commit 886192a

Browse files
committed
feature: @putout/operator-keyword: assert: isKeyword -> isLegacyKeyword
1 parent cedb0aa commit 886192a

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

packages/operator-keyword/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ isTSKeyword('implements');
5353
true;
5454
```
5555

56+
### `isLegacyKeyword`
57+
58+
> A previous version of `import attributes` used the `assert` keyword instead of with. The assertion feature is now non-standard.
59+
>
60+
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with)
61+
62+
```js
63+
import {operator} from 'putout';
64+
65+
const {isLegacyKeyword} = operator;
66+
67+
isLegacyKeyword('assert');
68+
// returns
69+
true;
70+
```
71+
5672
## License
5773

5874
MIT

packages/operator-keyword/lib/keyword.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const moduleDeclarations = [
22
'import',
33
'export',
4-
'assert',
54
'with',
65
];
76

7+
const legacyKeywords = ['assert'];
8+
89
const declarations = [
910
'const',
1011
'var',
@@ -89,3 +90,7 @@ export const isTSKeyword = (name) => {
8990

9091
return ts || tsReserved;
9192
};
93+
94+
export const isLegacyKeyword = (name) => {
95+
return legacyKeywords.includes(name);
96+
};

packages/operator-keyword/lib/keyword.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
isTSKeyword,
55
isDeclarationKeyword,
66
isConditionKeyword,
7+
isLegacyKeyword,
78
isModuleDeclarationKeyword,
89
isStatementKeyword,
910
} from './keyword.js';
@@ -186,6 +187,13 @@ test('putout: operator: isKeyword: default', (t) => {
186187
test('putout: operator: isKeyword: assert', (t) => {
187188
const result = isKeyword('assert');
188189

190+
t.notOk(result);
191+
t.end();
192+
});
193+
194+
test('putout: operator: isLegacyKeyword: assert', (t) => {
195+
const result = isLegacyKeyword('assert');
196+
189197
t.ok(result);
190198
t.end();
191199
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const assert = require('assert');
2+
3+
assert();

packages/plugin-variables/lib/extract-keywords/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,8 @@ test('putout: plugin-variables: extract-keywords: report: const', (t) => {
7878
t.report('const', `Extract 'const' from variable`);
7979
t.end();
8080
});
81+
82+
test('putout: plugin-variables: extract-keywords: no report: assert', (t) => {
83+
t.noReport('assert');
84+
t.end();
85+
});

0 commit comments

Comments
 (0)