@madenowhere/phaze-tsplugin 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rohan Rehman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs CHANGED
@@ -14,11 +14,19 @@
14
14
  // declared but its value is never read") and the editor shows it
15
15
  // fading / red.
16
16
  //
17
- // Fix: this plugin wraps the language service's `getSemanticDiagnostics`
18
- // and filters out TS6133 / TS6192 diagnostics whose unused name
19
- // matches a binding that the file consumes via a `use:NAME` JSX
20
- // attribute. Other unused-binding warnings still surface — only the
21
- // false-positive directive case is suppressed.
17
+ // Fix: this plugin wraps both `getSemanticDiagnostics` and
18
+ // `getSuggestionDiagnostics` and filters out TS6133 / TS6192 / TS6196
19
+ // diagnostics whose unused name matches a binding that the file
20
+ // consumes via a `use:NAME` JSX attribute. Other unused-binding
21
+ // warnings still surface — only the false-positive directive case is
22
+ // suppressed.
23
+ //
24
+ // Both channels are wrapped because TS routes the unused-binding
25
+ // warning differently depending on tsconfig: with `noUnusedLocals: true`
26
+ // the diagnostic lands in `getSemanticDiagnostics`; without it (the
27
+ // default and what most editors show as a faded/wavy hint) it lands
28
+ // in `getSuggestionDiagnostics`. Filtering only one channel leaves
29
+ // the other emitting the false positive.
22
30
  //
23
31
  // Wiring:
24
32
  // tsconfig.json:
@@ -71,32 +79,36 @@ const init = (arg) => ({
71
79
  const m = text.match(/^'([^']+)' is declared/);
72
80
  return m?.[1];
73
81
  };
82
+ const filterUnusedDirectives = (fileName, diags) => {
83
+ if (diags.length === 0)
84
+ return diags;
85
+ if (!diags.some((d) => UNUSED_DIAGNOSTIC_CODES.has(d.code)))
86
+ return diags;
87
+ const sf = target.getProgram()?.getSourceFile(fileName);
88
+ if (!sf)
89
+ return diags;
90
+ const useNames = collectUseDirectiveNames(sf);
91
+ if (useNames.size === 0)
92
+ return diags;
93
+ return diags.filter((d) => {
94
+ if (!UNUSED_DIAGNOSTIC_CODES.has(d.code))
95
+ return true;
96
+ const name = extractUnusedName(d);
97
+ // Suppress only when the unused binding name matches a
98
+ // directive consumed via use:NAME in this file.
99
+ return !name || !useNames.has(name);
100
+ });
101
+ };
102
+ const target = ls;
74
103
  return new Proxy(ls, {
75
- get(target, key) {
76
- if (key !== 'getSemanticDiagnostics') {
77
- return Reflect.get(target, key);
104
+ get(_t, key) {
105
+ if (key === 'getSemanticDiagnostics') {
106
+ return (fileName) => filterUnusedDirectives(fileName, target.getSemanticDiagnostics(fileName));
107
+ }
108
+ if (key === 'getSuggestionDiagnostics') {
109
+ return (fileName) => filterUnusedDirectives(fileName, target.getSuggestionDiagnostics(fileName));
78
110
  }
79
- return (fileName) => {
80
- const diags = target.getSemanticDiagnostics(fileName);
81
- if (diags.length === 0)
82
- return diags;
83
- if (!diags.some((d) => UNUSED_DIAGNOSTIC_CODES.has(d.code)))
84
- return diags;
85
- const sf = target.getProgram()?.getSourceFile(fileName);
86
- if (!sf)
87
- return diags;
88
- const useNames = collectUseDirectiveNames(sf);
89
- if (useNames.size === 0)
90
- return diags;
91
- return diags.filter((d) => {
92
- if (!UNUSED_DIAGNOSTIC_CODES.has(d.code))
93
- return true;
94
- const name = extractUnusedName(d);
95
- // Suppress only when the unused binding name matches a
96
- // directive consumed via use:NAME in this file.
97
- return !name || !useNames.has(name);
98
- });
99
- };
111
+ return Reflect.get(target, key);
100
112
  },
101
113
  });
102
114
  },
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,OAAO,MAAM,gCAAgC,CAAA;AAEzD,UAAU,gBAAgB;IACxB,eAAe,EAAE,OAAO,CAAC,eAAe,CAAA;IACxC,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,CAAA;IACrC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,CAAA;IAC/B,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAA;CACnC;AAED,UAAU,aAAa;IACrB,UAAU,EAAE,OAAO,OAAO,CAAA;CAC3B;AAED,UAAU,mBAAmB;IAC3B,CAAC,GAAG,EAAE,aAAa,GAAG;QACpB,MAAM,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAA;KACxD,CAAA;CACF;AAQD,QAAA,MAAM,IAAI,EAAE,mBAgEV,CAAA;AAEF,SAAS,IAAI,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,OAAO,MAAM,gCAAgC,CAAA;AAEzD,UAAU,gBAAgB;IACxB,eAAe,EAAE,OAAO,CAAC,eAAe,CAAA;IACxC,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,CAAA;IACrC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,CAAA;IAC/B,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAA;CACnC;AAED,UAAU,aAAa;IACrB,UAAU,EAAE,OAAO,OAAO,CAAA;CAC3B;AAED,UAAU,mBAAmB;IAC3B,CAAC,GAAG,EAAE,aAAa,GAAG;QACpB,MAAM,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAA;KACxD,CAAA;CACF;AAQD,QAAA,MAAM,IAAI,EAAE,mBA0EV,CAAA;AAEF,SAAS,IAAI,CAAA"}
package/dist/index.js CHANGED
@@ -14,11 +14,19 @@
14
14
  // declared but its value is never read") and the editor shows it
15
15
  // fading / red.
16
16
  //
17
- // Fix: this plugin wraps the language service's `getSemanticDiagnostics`
18
- // and filters out TS6133 / TS6192 diagnostics whose unused name
19
- // matches a binding that the file consumes via a `use:NAME` JSX
20
- // attribute. Other unused-binding warnings still surface — only the
21
- // false-positive directive case is suppressed.
17
+ // Fix: this plugin wraps both `getSemanticDiagnostics` and
18
+ // `getSuggestionDiagnostics` and filters out TS6133 / TS6192 / TS6196
19
+ // diagnostics whose unused name matches a binding that the file
20
+ // consumes via a `use:NAME` JSX attribute. Other unused-binding
21
+ // warnings still surface — only the false-positive directive case is
22
+ // suppressed.
23
+ //
24
+ // Both channels are wrapped because TS routes the unused-binding
25
+ // warning differently depending on tsconfig: with `noUnusedLocals: true`
26
+ // the diagnostic lands in `getSemanticDiagnostics`; without it (the
27
+ // default and what most editors show as a faded/wavy hint) it lands
28
+ // in `getSuggestionDiagnostics`. Filtering only one channel leaves
29
+ // the other emitting the false positive.
22
30
  //
23
31
  // Wiring:
24
32
  // tsconfig.json:
@@ -71,32 +79,36 @@ const init = (arg) => ({
71
79
  const m = text.match(/^'([^']+)' is declared/);
72
80
  return m?.[1];
73
81
  };
82
+ const filterUnusedDirectives = (fileName, diags) => {
83
+ if (diags.length === 0)
84
+ return diags;
85
+ if (!diags.some((d) => UNUSED_DIAGNOSTIC_CODES.has(d.code)))
86
+ return diags;
87
+ const sf = target.getProgram()?.getSourceFile(fileName);
88
+ if (!sf)
89
+ return diags;
90
+ const useNames = collectUseDirectiveNames(sf);
91
+ if (useNames.size === 0)
92
+ return diags;
93
+ return diags.filter((d) => {
94
+ if (!UNUSED_DIAGNOSTIC_CODES.has(d.code))
95
+ return true;
96
+ const name = extractUnusedName(d);
97
+ // Suppress only when the unused binding name matches a
98
+ // directive consumed via use:NAME in this file.
99
+ return !name || !useNames.has(name);
100
+ });
101
+ };
102
+ const target = ls;
74
103
  return new Proxy(ls, {
75
- get(target, key) {
76
- if (key !== 'getSemanticDiagnostics') {
77
- return Reflect.get(target, key);
104
+ get(_t, key) {
105
+ if (key === 'getSemanticDiagnostics') {
106
+ return (fileName) => filterUnusedDirectives(fileName, target.getSemanticDiagnostics(fileName));
107
+ }
108
+ if (key === 'getSuggestionDiagnostics') {
109
+ return (fileName) => filterUnusedDirectives(fileName, target.getSuggestionDiagnostics(fileName));
78
110
  }
79
- return (fileName) => {
80
- const diags = target.getSemanticDiagnostics(fileName);
81
- if (diags.length === 0)
82
- return diags;
83
- if (!diags.some((d) => UNUSED_DIAGNOSTIC_CODES.has(d.code)))
84
- return diags;
85
- const sf = target.getProgram()?.getSourceFile(fileName);
86
- if (!sf)
87
- return diags;
88
- const useNames = collectUseDirectiveNames(sf);
89
- if (useNames.size === 0)
90
- return diags;
91
- return diags.filter((d) => {
92
- if (!UNUSED_DIAGNOSTIC_CODES.has(d.code))
93
- return true;
94
- const name = extractUnusedName(d);
95
- // Suppress only when the unused binding name matches a
96
- // directive consumed via use:NAME in this file.
97
- return !name || !useNames.has(name);
98
- });
99
- };
111
+ return Reflect.get(target, key);
100
112
  },
101
113
  });
102
114
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madenowhere/phaze-tsplugin",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "TypeScript language-service plugin that teaches the IDE about Phaze JSX `use:` directives — suppresses TS6133 'unused binding' diagnostics when the binding is consumed by a `use:X` JSX attribute.",
5
5
  "license": "MIT",
6
6
  "author": "madenowhere",
@@ -24,15 +24,13 @@
24
24
  "dist",
25
25
  "README.md"
26
26
  ],
27
- "scripts": {
28
- "build": "tsc -p tsconfig.json && node -e \"const fs=require('fs');const c=fs.readFileSync('dist/index.js','utf8').replace(/export\\s*=\\s*(\\w+);?/,'module.exports=$1;');fs.writeFileSync('dist/index.cjs',c);\"",
29
- "dev": "tsc -p tsconfig.json --watch"
30
- },
31
27
  "peerDependencies": {
32
28
  "typescript": ">=5.0.0"
33
29
  },
34
30
  "peerDependenciesMeta": {
35
- "typescript": { "optional": false }
31
+ "typescript": {
32
+ "optional": false
33
+ }
36
34
  },
37
35
  "devDependencies": {
38
36
  "typescript": "^6.0.0"
@@ -44,5 +42,9 @@
44
42
  "plugin",
45
43
  "jsx",
46
44
  "directives"
47
- ]
48
- }
45
+ ],
46
+ "scripts": {
47
+ "build": "tsc -p tsconfig.json && node -e \"const fs=require('fs');const c=fs.readFileSync('dist/index.js','utf8').replace(/export\\s*=\\s*(\\w+);?/,'module.exports=$1;');fs.writeFileSync('dist/index.cjs',c);\"",
48
+ "dev": "tsc -p tsconfig.json --watch"
49
+ }
50
+ }