@tslite/explain 0.2.1 → 0.3.0
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/dist/index.cjs +1 -1
- package/dist/index.d.cts +27 -3
- package/dist/index.d.ts +27 -3
- package/dist/index.js +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var core=require('@tslite/core'),printer=require('@tslite/printer'),operators=require('@tslite/operators');var
|
|
1
|
+
'use strict';var core=require('@tslite/core'),printer=require('@tslite/printer'),operators=require('@tslite/operators');var a="checker D9 / docs/SCOPE-BOUNDARY.md";function w(e,n){let t=M(e);return n.diagnostics.map(o=>{let s=m(o,t);return s?{...o,help:s}:o})}function m(e,n){let t=e.node;switch(t.type){case "NewExpression":return E(t);case "ClassDeclaration":case "ClassExpression":return O();case "FunctionDeclaration":case "FunctionExpression":return T();case "ThisExpression":return H();case "MemberExpression":return e.code==="forbidden-member"?k(t):N(e,t,n)}}function N(e,n,t){if(e.code!=="no-such-member"&&e.code!=="not-object")return;let o=g(n);if(!o)return;let s=operators.jsMethodReplacements[o];if(s)return D(n,o,s,t);if(operators.knownProtoMembersWithoutOperator.has(o))return B(o)}function D(e,n,t,o){let s=printer.print(e.object),i=o.get(e),l=i?.type==="CallExpression"&&i.callee===e,y=l?i.arguments.map(f=>printer.print(f)):[],r=l?i:e,c=t.call(s,y),u=printer.print(r),d=r.loc?{start:r.loc.start,end:r.loc.end}:void 0;return {reason:"proto-member",category:"portability",explain:`${t.on==="array"?"Arrays":t.on==="string"?"Strings":"Values"} in TSL have no \`.${n}\` method (prototype member). TSL is FP-first and PORTABLE: \`.${n}\` does not translate cleanly to the target (in Python, for instance, it is a function). This is not a language bug \u2014 it is the model.`,suggestion:`Use the \`${t.operator}\` operator (@tslite/operators): \`${c}\`.`,fix:d?{from:u,to:c,range:d}:{from:u,to:c},docs:a}}function B(e){return {reason:"proto-member",category:"portability",explain:`\`.${e}\` is a JS prototype method/property \u2014 TSL is FP-first and immutable, so array/string/object methods are not vocabulary. This is not a language bug \u2014 it is the model.`,suggestion:"Rewrite it functionally with @tslite/operators (map/filter/reduce/\u2026), or use the imperative capability if you truly need to mutate.",docs:a}}function k(e){return {reason:"forbidden-substrate",category:"js-ism",explain:`\`.${g(e)??"constructor/prototype/__proto__"}\` is JS runtime substrate (inheritance/prototype) \u2014 it does not exist in TSL, which is FP-first and portable. Forbidden by identity + portability (and it closes the sandbox escape). This is not a language bug \u2014 it is the model.`,docs:a}}function E(e){let n=e.callee,t=n?.type==="Identifier"?n.name:"X";return {reason:"no-new",category:"js-ism",explain:"TSL has no `new` and no classes \u2014 it is FP-first (no OO). `new` was removed on purpose: native capabilities come in as FACTORY functions via DI. Not a language bug.",suggestion:`Inject a factory and call \`${t.charAt(0).toLowerCase()+t.slice(1)}(\u2026)\` instead of \`new ${t}(\u2026)\`.`,docs:a}}function O(){return {reason:"no-class",category:"js-ism",explain:"`class` does not exist in TSL \u2014 it is FP-first, no OO. An instance is just an object with props; behavior comes from functions. This is not a language bug \u2014 it is the model.",suggestion:'Model with objects + functions (a factory function via DI for "methods").',docs:a}}function H(){return {reason:"no-this",category:"js-ism",explain:"`this` does not exist in TSL \u2014 no OO, no implicit receiver. This is not a language bug \u2014 it is the model.",suggestion:"Pass the data as an explicit ARGUMENT instead of `this`.",docs:a}}function T(){return {reason:"no-function-expr",category:"js-ism",explain:"Only ARROW functions are functions in TSL (`(x) => \u2026`). `function(){}` is out (it brings `this`/`arguments`/construction \u2014 OO substrate). This is not a language bug \u2014 it is the model.",suggestion:"Use an arrow: `const f = (x) => \u2026`.",docs:a}}function g(e){if(!e.computed)return e.property.name;let n=e.property;return n.type==="Literal"&&typeof n.value=="string"?n.value:void 0}function M(e){let n=new WeakMap;return core.walk(e,{"*":(t,o)=>{o&&n.set(t,o);}}),n}exports.explain=w;exports.helpFor=m;
|
package/dist/index.d.cts
CHANGED
|
@@ -3,6 +3,15 @@ import { Diagnostic, CheckResult } from '@tslite/checker';
|
|
|
3
3
|
|
|
4
4
|
/** Por que o erro aconteceu — a "raiz JS-ism" que o help explica. */
|
|
5
5
|
type JsIsmReason = "proto-member" | "no-new" | "no-class" | "no-this" | "no-function-expr" | "forbidden-substrate";
|
|
6
|
+
/**
|
|
7
|
+
* A chave estável de i18n (ver E2).
|
|
8
|
+
*
|
|
9
|
+
* Houve aqui um `SyntaxGapReason` (`type-args-not-supported`), mitigação para
|
|
10
|
+
* `f<T>(x)` não existir na gramática. **Saiu porque a lacuna foi fechada** — hoje
|
|
11
|
+
* o parser lê argumento de tipo de verdade (parser TODO / checker TC27). A
|
|
12
|
+
* categoria volta quando houver um buraco de gramática real para descrever.
|
|
13
|
+
*/
|
|
14
|
+
type HelpReason = JsIsmReason;
|
|
6
15
|
/** A CLASSE do porquê — deixa uma UI didática renderizar diferente de erro de tipo. */
|
|
7
16
|
type HelpCategory = "js-ism" | "portability" | "capability-off";
|
|
8
17
|
/** O help auxiliar: prosa explicativa + sugestão + auto-fix aplicável (por IA/editor).
|
|
@@ -10,16 +19,31 @@ type HelpCategory = "js-ism" | "portability" | "capability-off";
|
|
|
10
19
|
* mensagens do checker). `reason` é a CHAVE estável de tradução: um add-on de i18n no
|
|
11
20
|
* frontend mapeia `reason` (+ os campos estruturados) → idioma, sem tocar isto. */
|
|
12
21
|
interface DiagnosticHelp {
|
|
13
|
-
readonly reason:
|
|
22
|
+
readonly reason: HelpReason;
|
|
14
23
|
readonly category: HelpCategory;
|
|
15
24
|
/** "Why this is NOT a language bug" — default prose (English). */
|
|
16
25
|
readonly explain: string;
|
|
17
26
|
/** The correct idiom (e.g. "Use the `length(xs)` operator"). */
|
|
18
27
|
readonly suggestion?: string;
|
|
19
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Reescrita mecânica: `from` → `to` (aplicável por code-action ou por uma IA).
|
|
30
|
+
* `range` é o trecho EXATO a substituir (convenção TSLite: linha 1-based, coluna
|
|
31
|
+
* 0-based, fim exclusivo) — presente só quando o nó tem `loc`, isto é, quando o
|
|
32
|
+
* AST veio de autoria TEXTUAL. Em AST de builders (nocode) não há posição.
|
|
33
|
+
*/
|
|
20
34
|
readonly fix?: {
|
|
21
35
|
readonly from: string;
|
|
22
36
|
readonly to: string;
|
|
37
|
+
readonly range?: {
|
|
38
|
+
readonly start: {
|
|
39
|
+
readonly line: number;
|
|
40
|
+
readonly column: number;
|
|
41
|
+
};
|
|
42
|
+
readonly end: {
|
|
43
|
+
readonly line: number;
|
|
44
|
+
readonly column: number;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
23
47
|
};
|
|
24
48
|
/** Âncora de documentação. */
|
|
25
49
|
readonly docs?: string;
|
|
@@ -37,4 +61,4 @@ declare function explain(ast: BaseNode, result: CheckResult): ExplainedDiagnosti
|
|
|
37
61
|
/** O `help` de um diagnóstico isolado, dado o mapa de pais (ou `undefined`). */
|
|
38
62
|
declare function helpFor(d: Diagnostic, parents: WeakMap<BaseNode, BaseNode>): DiagnosticHelp | undefined;
|
|
39
63
|
|
|
40
|
-
export { type DiagnosticHelp, type ExplainedDiagnostic, type HelpCategory, type JsIsmReason, explain, helpFor };
|
|
64
|
+
export { type DiagnosticHelp, type ExplainedDiagnostic, type HelpCategory, type HelpReason, type JsIsmReason, explain, helpFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,15 @@ import { Diagnostic, CheckResult } from '@tslite/checker';
|
|
|
3
3
|
|
|
4
4
|
/** Por que o erro aconteceu — a "raiz JS-ism" que o help explica. */
|
|
5
5
|
type JsIsmReason = "proto-member" | "no-new" | "no-class" | "no-this" | "no-function-expr" | "forbidden-substrate";
|
|
6
|
+
/**
|
|
7
|
+
* A chave estável de i18n (ver E2).
|
|
8
|
+
*
|
|
9
|
+
* Houve aqui um `SyntaxGapReason` (`type-args-not-supported`), mitigação para
|
|
10
|
+
* `f<T>(x)` não existir na gramática. **Saiu porque a lacuna foi fechada** — hoje
|
|
11
|
+
* o parser lê argumento de tipo de verdade (parser TODO / checker TC27). A
|
|
12
|
+
* categoria volta quando houver um buraco de gramática real para descrever.
|
|
13
|
+
*/
|
|
14
|
+
type HelpReason = JsIsmReason;
|
|
6
15
|
/** A CLASSE do porquê — deixa uma UI didática renderizar diferente de erro de tipo. */
|
|
7
16
|
type HelpCategory = "js-ism" | "portability" | "capability-off";
|
|
8
17
|
/** O help auxiliar: prosa explicativa + sugestão + auto-fix aplicável (por IA/editor).
|
|
@@ -10,16 +19,31 @@ type HelpCategory = "js-ism" | "portability" | "capability-off";
|
|
|
10
19
|
* mensagens do checker). `reason` é a CHAVE estável de tradução: um add-on de i18n no
|
|
11
20
|
* frontend mapeia `reason` (+ os campos estruturados) → idioma, sem tocar isto. */
|
|
12
21
|
interface DiagnosticHelp {
|
|
13
|
-
readonly reason:
|
|
22
|
+
readonly reason: HelpReason;
|
|
14
23
|
readonly category: HelpCategory;
|
|
15
24
|
/** "Why this is NOT a language bug" — default prose (English). */
|
|
16
25
|
readonly explain: string;
|
|
17
26
|
/** The correct idiom (e.g. "Use the `length(xs)` operator"). */
|
|
18
27
|
readonly suggestion?: string;
|
|
19
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Reescrita mecânica: `from` → `to` (aplicável por code-action ou por uma IA).
|
|
30
|
+
* `range` é o trecho EXATO a substituir (convenção TSLite: linha 1-based, coluna
|
|
31
|
+
* 0-based, fim exclusivo) — presente só quando o nó tem `loc`, isto é, quando o
|
|
32
|
+
* AST veio de autoria TEXTUAL. Em AST de builders (nocode) não há posição.
|
|
33
|
+
*/
|
|
20
34
|
readonly fix?: {
|
|
21
35
|
readonly from: string;
|
|
22
36
|
readonly to: string;
|
|
37
|
+
readonly range?: {
|
|
38
|
+
readonly start: {
|
|
39
|
+
readonly line: number;
|
|
40
|
+
readonly column: number;
|
|
41
|
+
};
|
|
42
|
+
readonly end: {
|
|
43
|
+
readonly line: number;
|
|
44
|
+
readonly column: number;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
23
47
|
};
|
|
24
48
|
/** Âncora de documentação. */
|
|
25
49
|
readonly docs?: string;
|
|
@@ -37,4 +61,4 @@ declare function explain(ast: BaseNode, result: CheckResult): ExplainedDiagnosti
|
|
|
37
61
|
/** O `help` de um diagnóstico isolado, dado o mapa de pais (ou `undefined`). */
|
|
38
62
|
declare function helpFor(d: Diagnostic, parents: WeakMap<BaseNode, BaseNode>): DiagnosticHelp | undefined;
|
|
39
63
|
|
|
40
|
-
export { type DiagnosticHelp, type ExplainedDiagnostic, type HelpCategory, type JsIsmReason, explain, helpFor };
|
|
64
|
+
export { type DiagnosticHelp, type ExplainedDiagnostic, type HelpCategory, type HelpReason, type JsIsmReason, explain, helpFor };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {walk}from'@tslite/core';import {print}from'@tslite/printer';import {jsMethodReplacements,knownProtoMembersWithoutOperator}from'@tslite/operators';var
|
|
1
|
+
import {walk}from'@tslite/core';import {print}from'@tslite/printer';import {jsMethodReplacements,knownProtoMembersWithoutOperator}from'@tslite/operators';var a="checker D9 / docs/SCOPE-BOUNDARY.md";function w(e,n){let t=M(e);return n.diagnostics.map(o=>{let s=m(o,t);return s?{...o,help:s}:o})}function m(e,n){let t=e.node;switch(t.type){case "NewExpression":return E(t);case "ClassDeclaration":case "ClassExpression":return O();case "FunctionDeclaration":case "FunctionExpression":return T();case "ThisExpression":return H();case "MemberExpression":return e.code==="forbidden-member"?k(t):N(e,t,n)}}function N(e,n,t){if(e.code!=="no-such-member"&&e.code!=="not-object")return;let o=g(n);if(!o)return;let s=jsMethodReplacements[o];if(s)return D(n,o,s,t);if(knownProtoMembersWithoutOperator.has(o))return B(o)}function D(e,n,t,o){let s=print(e.object),i=o.get(e),l=i?.type==="CallExpression"&&i.callee===e,y=l?i.arguments.map(f=>print(f)):[],r=l?i:e,c=t.call(s,y),u=print(r),d=r.loc?{start:r.loc.start,end:r.loc.end}:void 0;return {reason:"proto-member",category:"portability",explain:`${t.on==="array"?"Arrays":t.on==="string"?"Strings":"Values"} in TSL have no \`.${n}\` method (prototype member). TSL is FP-first and PORTABLE: \`.${n}\` does not translate cleanly to the target (in Python, for instance, it is a function). This is not a language bug \u2014 it is the model.`,suggestion:`Use the \`${t.operator}\` operator (@tslite/operators): \`${c}\`.`,fix:d?{from:u,to:c,range:d}:{from:u,to:c},docs:a}}function B(e){return {reason:"proto-member",category:"portability",explain:`\`.${e}\` is a JS prototype method/property \u2014 TSL is FP-first and immutable, so array/string/object methods are not vocabulary. This is not a language bug \u2014 it is the model.`,suggestion:"Rewrite it functionally with @tslite/operators (map/filter/reduce/\u2026), or use the imperative capability if you truly need to mutate.",docs:a}}function k(e){return {reason:"forbidden-substrate",category:"js-ism",explain:`\`.${g(e)??"constructor/prototype/__proto__"}\` is JS runtime substrate (inheritance/prototype) \u2014 it does not exist in TSL, which is FP-first and portable. Forbidden by identity + portability (and it closes the sandbox escape). This is not a language bug \u2014 it is the model.`,docs:a}}function E(e){let n=e.callee,t=n?.type==="Identifier"?n.name:"X";return {reason:"no-new",category:"js-ism",explain:"TSL has no `new` and no classes \u2014 it is FP-first (no OO). `new` was removed on purpose: native capabilities come in as FACTORY functions via DI. Not a language bug.",suggestion:`Inject a factory and call \`${t.charAt(0).toLowerCase()+t.slice(1)}(\u2026)\` instead of \`new ${t}(\u2026)\`.`,docs:a}}function O(){return {reason:"no-class",category:"js-ism",explain:"`class` does not exist in TSL \u2014 it is FP-first, no OO. An instance is just an object with props; behavior comes from functions. This is not a language bug \u2014 it is the model.",suggestion:'Model with objects + functions (a factory function via DI for "methods").',docs:a}}function H(){return {reason:"no-this",category:"js-ism",explain:"`this` does not exist in TSL \u2014 no OO, no implicit receiver. This is not a language bug \u2014 it is the model.",suggestion:"Pass the data as an explicit ARGUMENT instead of `this`.",docs:a}}function T(){return {reason:"no-function-expr",category:"js-ism",explain:"Only ARROW functions are functions in TSL (`(x) => \u2026`). `function(){}` is out (it brings `this`/`arguments`/construction \u2014 OO substrate). This is not a language bug \u2014 it is the model.",suggestion:"Use an arrow: `const f = (x) => \u2026`.",docs:a}}function g(e){if(!e.computed)return e.property.name;let n=e.property;return n.type==="Literal"&&typeof n.value=="string"?n.value:void 0}function M(e){let n=new WeakMap;return walk(e,{"*":(t,o)=>{o&&n.set(t,o);}}),n}export{w as explain,m as helpFor};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tslite/explain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "TSLite explain — enriches type-check diagnostics with 'why it is NOT a language bug' help for JS/OO habits (proto members, new, class), with operator suggestions and auto-fixes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@tslite/core": "0.2.0",
|
|
43
|
-
"@tslite/checker": "0.2.1",
|
|
44
43
|
"@tslite/printer": "0.2.0",
|
|
45
|
-
"@tslite/
|
|
46
|
-
"@tslite/type-core": "0.
|
|
44
|
+
"@tslite/checker": "0.3.0",
|
|
45
|
+
"@tslite/type-core": "0.3.0",
|
|
46
|
+
"@tslite/operators": "0.3.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@tslite/parser": "0.
|
|
49
|
+
"@tslite/parser": "0.3.0"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "tsup",
|