@fulcro/transform-core 0.3.0 → 0.4.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.d.ts +1 -1
- package/dist/shared/index.d.ts +18 -0
- package/dist/shared/index.js +16 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -17,5 +17,5 @@
|
|
|
17
17
|
* other.
|
|
18
18
|
*/
|
|
19
19
|
export { createFileTransformer, type FileTransformer, type TransformCoreOptions, } from './program/index.js';
|
|
20
|
-
export { type CallRewriter, IDENTIFIER_PATTERN, isOwnedCall, isTupleType, type RewriteContext, utilityModuleSegment, } from './shared/index.js';
|
|
20
|
+
export { type CallForm, type CallRewriter, IDENTIFIER_PATTERN, isOwnedCall, isTupleType, type RewriteContext, utilityModuleSegment, } from './shared/index.js';
|
|
21
21
|
export { createTransformer, type TransformerFactory, type TransformerOptions, } from './transformer/index.js';
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -24,12 +24,30 @@ export interface RewriteContext {
|
|
|
24
24
|
*/
|
|
25
25
|
readonly visit: (node: typescript.Node) => typescript.Node;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* How a rewritten call is written at the call site.
|
|
29
|
+
*
|
|
30
|
+
* A free function is reached through an identifier the consumer imported; a
|
|
31
|
+
* method is reached through whatever expression it is called on, so there is no
|
|
32
|
+
* import to follow and the receiver could be anything. Both are resolved the
|
|
33
|
+
* same way in the end — by following the symbol back to its declaration — but
|
|
34
|
+
* the node to ask about differs.
|
|
35
|
+
*/
|
|
36
|
+
export type CallForm = 'function' | 'method';
|
|
27
37
|
/** Rewrites the calls of a single utility. */
|
|
28
38
|
export interface CallRewriter {
|
|
29
39
|
/** Name the exported function is called by. */
|
|
30
40
|
readonly functionName: string;
|
|
31
41
|
/** Path segment identifying the module that declares it. */
|
|
32
42
|
readonly moduleSegment: string;
|
|
43
|
+
/**
|
|
44
|
+
* Shape of the call, defaulting to a free function.
|
|
45
|
+
*
|
|
46
|
+
* `'method'` claims `something.name(…)` rather than `name(…)`, which is what
|
|
47
|
+
* lets a library rewrite calls on its own types — `sequence.ofType<T>()` —
|
|
48
|
+
* where nothing was imported by that name.
|
|
49
|
+
*/
|
|
50
|
+
readonly callForm?: CallForm;
|
|
33
51
|
/**
|
|
34
52
|
* Rewrites one call.
|
|
35
53
|
*
|
package/dist/shared/index.js
CHANGED
|
@@ -72,11 +72,24 @@ exports.utilityModuleSegment = utilityModuleSegment;
|
|
|
72
72
|
* @returns `true` when the call targets the function of that rewriter.
|
|
73
73
|
*/
|
|
74
74
|
const isOwnedCall = (call, checker, rewriter) => {
|
|
75
|
-
|
|
75
|
+
// The node carrying the name differs between the two forms: an identifier
|
|
76
|
+
// standing on its own, or the member half of a property access. Everything
|
|
77
|
+
// after this point is the same question asked of that node.
|
|
78
|
+
// `MemberName` rather than `Identifier`: a property access can also name a
|
|
79
|
+
// private member, which carries a `text` like any other and simply never
|
|
80
|
+
// matches one of ours.
|
|
81
|
+
const named = rewriter.callForm === 'method'
|
|
82
|
+
? typescript_1.default.isPropertyAccessExpression(call.expression)
|
|
83
|
+
? call.expression.name
|
|
84
|
+
: null
|
|
85
|
+
: typescript_1.default.isIdentifier(call.expression)
|
|
86
|
+
? call.expression
|
|
87
|
+
: null;
|
|
88
|
+
if (named === null)
|
|
76
89
|
return false;
|
|
77
|
-
if (
|
|
90
|
+
if (named.text !== rewriter.functionName)
|
|
78
91
|
return false;
|
|
79
|
-
const symbol = checker.getSymbolAtLocation(
|
|
92
|
+
const symbol = checker.getSymbolAtLocation(named);
|
|
80
93
|
const resolved = symbol !== undefined && (symbol.flags & typescript_1.default.SymbolFlags.Alias) !== 0
|
|
81
94
|
? checker.getAliasedSymbol(symbol)
|
|
82
95
|
: symbol;
|
package/package.json
CHANGED