@signaltree/callable-syntax 4.0.4 → 4.0.6

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/package.json CHANGED
@@ -1,36 +1,37 @@
1
1
  {
2
2
  "name": "@signaltree/callable-syntax",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
4
4
  "description": "Optional zero-runtime callable syntax transform for SignalTree unified leaf API.",
5
5
  "license": "BSL-1.1",
6
6
  "type": "commonjs",
7
- "main": "./dist/packages/callable-syntax/src/index.js",
8
- "module": "./dist/packages/callable-syntax/src/index.js",
9
- "types": "./dist/packages/callable-syntax/src/index.d.ts",
7
+ "main": "./src/index.js",
8
+ "module": "./src/index.js",
9
+ "types": "./src/index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
- "types": "./dist/packages/callable-syntax/src/index.d.ts",
13
- "require": "./dist/packages/callable-syntax/src/index.js",
14
- "import": "./dist/packages/callable-syntax/src/index.js"
12
+ "types": "./src/index.d.ts",
13
+ "require": "./src/index.js",
14
+ "import": "./src/index.js"
15
15
  },
16
16
  "./vite": {
17
- "types": "./dist/packages/callable-syntax/src/lib/vite-plugin.d.ts",
18
- "require": "./dist/packages/callable-syntax/src/lib/vite-plugin.js",
19
- "import": "./dist/packages/callable-syntax/src/lib/vite-plugin.js"
17
+ "types": "./src/lib/vite-plugin.d.ts",
18
+ "require": "./src/lib/vite-plugin.js",
19
+ "import": "./src/lib/vite-plugin.js"
20
20
  },
21
21
  "./webpack": {
22
- "types": "./dist/packages/callable-syntax/src/lib/webpack-plugin.d.ts",
23
- "require": "./dist/packages/callable-syntax/src/lib/webpack-plugin.js",
24
- "import": "./dist/packages/callable-syntax/src/lib/webpack-plugin.js"
22
+ "types": "./src/lib/webpack-plugin.d.ts",
23
+ "require": "./src/lib/webpack-plugin.js",
24
+ "import": "./src/lib/webpack-plugin.js"
25
25
  },
26
26
  "./augmentation": {
27
- "types": "./dist/packages/callable-syntax/src/augmentation.d.ts",
28
- "require": "./dist/packages/callable-syntax/src/augmentation.js",
29
- "import": "./dist/packages/callable-syntax/src/augmentation.js"
27
+ "types": "./src/augmentation.d.ts",
28
+ "require": "./src/augmentation.js",
29
+ "import": "./src/augmentation.js"
30
30
  }
31
31
  },
32
32
  "files": [
33
- "dist"
33
+ "src",
34
+ "packages/callable-syntax/README.md"
34
35
  ],
35
36
  "sideEffects": false,
36
37
  "dependencies": {
@@ -0,0 +1,157 @@
1
+ ## @signaltree/callable-syntax
2
+
3
+ Zero-runtime callable syntax transform for SignalTree. Enables elegant developer experience that compiles away completely.
4
+
5
+ ### What It Does
6
+
7
+ ```typescript
8
+ // You write (with great DX):
9
+ tree.$.user.name('Alice');
10
+ tree.$.count((n) => n + 1);
11
+
12
+ // Transform converts to (zero overhead):
13
+ tree.$.user.name.set('Alice');
14
+ tree.$.count.update((n) => n + 1);
15
+
16
+ // Getters work unchanged:
17
+ const name = tree.$.user.name();
18
+ ```
19
+
20
+ ### Installation
21
+
22
+ ```bash
23
+ npm install @signaltree/core
24
+ npm install -D @signaltree/callable-syntax
25
+ ```
26
+
27
+ **Key**: Install as dev dependency since it's a build-time tool only.
28
+
29
+ ### Setup for Teams
30
+
31
+ #### Angular Projects
32
+
33
+ ```typescript
34
+ // angular.json - add to build options
35
+ {
36
+ "build": {
37
+ "options": {
38
+ "customWebpackConfig": {
39
+ "path": "./webpack.extra.js"
40
+ }
41
+ }
42
+ }
43
+ }
44
+ ```
45
+
46
+ ```javascript
47
+ // webpack.extra.js
48
+ const { SignalTreeWebpackPlugin } = require('@signaltree/callable-syntax/webpack');
49
+
50
+ module.exports = {
51
+ plugins: [new SignalTreeWebpackPlugin()],
52
+ };
53
+ ```
54
+
55
+ #### Vite Projects
56
+
57
+ ```typescript
58
+ // vite.config.ts
59
+ import { defineConfig } from 'vite';
60
+ import { signalTreeSyntaxTransform } from '@signaltree/callable-syntax/vite';
61
+
62
+ export default defineConfig({
63
+ plugins: [signalTreeSyntaxTransform()],
64
+ });
65
+ ```
66
+
67
+ ### Webpack
68
+
69
+ ````ts
70
+ #### Webpack (Manual Setup)
71
+
72
+ ```javascript
73
+ // webpack.config.js
74
+ const { SignalTreeTransform } = require('@signaltree/callable-syntax/transform');
75
+
76
+ module.exports = {
77
+ module: {
78
+ rules: [
79
+ {
80
+ test: /\.tsx?$/,
81
+ use: [
82
+ 'ts-loader',
83
+ {
84
+ loader: 'babel-loader',
85
+ options: {
86
+ plugins: [SignalTreeTransform]
87
+ }
88
+ }
89
+ ]
90
+ }
91
+ ]
92
+ }
93
+ };
94
+ ````
95
+
96
+ #### Babel Configuration
97
+
98
+ ```json
99
+ // .babelrc or babel.config.json
100
+ {
101
+ "plugins": ["@signaltree/callable-syntax/babel-plugin"]
102
+ }
103
+ ```
104
+
105
+ ### Development Workflow
106
+
107
+ The transform only affects build output - your TypeScript will still type-check correctly with callable syntax because SignalTree includes the necessary type augmentations.
108
+
109
+ ```typescript
110
+ import { createSignalStore } from '@signaltree/core';
111
+
112
+ const store = createSignalStore({
113
+ todos: [] as Todo[],
114
+ filter: 'all' as 'all' | 'active' | 'completed',
115
+ });
116
+
117
+ // TypeScript understands both forms:
118
+ store.$.todos(newTodos); // Callable syntax (transforms away)
119
+ store.$.todos.set(newTodos); // Direct syntax (stays as-is)
120
+
121
+ // Getters always stay the same:
122
+ const currentTodos = store.$.todos();
123
+ ```
124
+
125
+ ### Production Build
126
+
127
+ In production builds, only direct Angular signal calls remain - no runtime overhead, no wrapper functions, no Proxy objects. The callable syntax is purely developer experience sugar.
128
+
129
+ ```
130
+
131
+ ### TypeScript
132
+
133
+ No per-file imports required in this repo. Types are loaded via root `tsconfig`:
134
+
135
+ - `@signaltree/core` defines callable `NodeAccessor<T>`.
136
+ - Leaves are callable `WritableSignal`s at the type level for consistent DX.
137
+ If you’re consuming externally, include `@signaltree/callable-syntax/augmentation` in your `compilerOptions.types`.
138
+
139
+ ### Configuration Options
140
+
141
+ | Option | Description | Default |
142
+ | --------------- | ------------------------------------------- | ----------------------------------------------- | -------- | --------- |
143
+ | include | Files to include (RegExp) | /src/.\*\.(t | j)sx?$/ |
144
+ | exclude | Files to exclude (RegExp) | /node_modules | \.spec\. | \.test\./ |
145
+ | rootIdentifiers | Root variable names containing a SignalTree | ['tree'] (exported as DEFAULT_ROOT_IDENTIFIERS) |
146
+ | debug | Log transformed counts | false |
147
+
148
+ ### Notes
149
+
150
+ - Pure dev-time; adds 0 bytes to production bundle.
151
+ - Does not modify runtime; you can mix standard `.set()` / `.update()` calls freely.
152
+ - Safe fallback: if plugin absent, callable writes just become runtime errors you can catch in CI (recommend lint rule if enforcing).
153
+
154
+ ### License
155
+
156
+ Business Source License 1.1 (BSL-1.1) – converts to MIT on Change Date per root project license.
157
+ ```
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=augmentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"augmentation.js","sourceRoot":"","sources":["../../../../packages/callable-syntax/src/augmentation.ts"],"names":[],"mappings":""}
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './lib/ast-transform';
2
+ export * from './lib/vite-plugin';
3
+ export * from './lib/webpack-plugin';
4
+ export * from './augmentation';
package/src/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/ast-transform"), exports);
5
+ tslib_1.__exportStar(require("./lib/vite-plugin"), exports);
6
+ tslib_1.__exportStar(require("./lib/webpack-plugin"), exports);
7
+ tslib_1.__exportStar(require("./augmentation"), exports);
8
+ // Augmentation is exported behind a path; users can `import '@signaltree/callable-syntax/augmentation'` if desired.
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/callable-syntax/src/index.ts"],"names":[],"mappings":";;;AAAA,8DAAoC;AACpC,4DAAkC;AAClC,+DAAqC;AACrC,yDAA+B;AAC/B,oHAAoH"}
@@ -0,0 +1,28 @@
1
+ export interface TransformOptions {
2
+ /** Root variable names that contain SignalTree instances (default: ['tree']) */
3
+ readonly rootIdentifiers?: string[];
4
+ /** Enable debug logging for transformed calls */
5
+ readonly debug?: boolean;
6
+ }
7
+ export interface TransformResult {
8
+ /** The transformed code */
9
+ code: string;
10
+ /** Number of calls that were transformed */
11
+ transformed: number;
12
+ }
13
+ export declare const DEFAULT_ROOT_IDENTIFIERS: string[];
14
+ /**
15
+ * Transforms SignalTree callable syntax to explicit .set/.update method calls
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * // Input:
20
+ * tree.$.user.name('John');
21
+ * tree.$.count(n => n + 1);
22
+ *
23
+ * // Output:
24
+ * tree.$.user.name.set('John');
25
+ * tree.$.count.update(n => n + 1);
26
+ * ```
27
+ */
28
+ export declare function transformCode(source: string, options?: TransformOptions): TransformResult;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_ROOT_IDENTIFIERS = void 0;
4
+ exports.transformCode = transformCode;
5
+ const tslib_1 = require("tslib");
6
+ const generator_1 = tslib_1.__importDefault(require("@babel/generator"));
7
+ const parser_1 = require("@babel/parser");
8
+ const traverse_1 = tslib_1.__importDefault(require("@babel/traverse"));
9
+ const t = tslib_1.__importStar(require("@babel/types"));
10
+ exports.DEFAULT_ROOT_IDENTIFIERS = ['tree'];
11
+ /**
12
+ * Transforms SignalTree callable syntax to explicit .set/.update method calls
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * // Input:
17
+ * tree.$.user.name('John');
18
+ * tree.$.count(n => n + 1);
19
+ *
20
+ * // Output:
21
+ * tree.$.user.name.set('John');
22
+ * tree.$.count.update(n => n + 1);
23
+ * ```
24
+ */
25
+ function transformCode(source, options = {}) {
26
+ var _a;
27
+ const rootIds = ((_a = options.rootIdentifiers) === null || _a === void 0 ? void 0 : _a.length)
28
+ ? options.rootIdentifiers
29
+ : exports.DEFAULT_ROOT_IDENTIFIERS;
30
+ const ast = parseSourceCode(source);
31
+ let transformCount = 0;
32
+ (0, traverse_1.default)(ast, {
33
+ CallExpression(path) {
34
+ const { node } = path;
35
+ if (!t.isCallExpression(node))
36
+ return;
37
+ if (shouldTransformCallExpression(node, rootIds)) {
38
+ const transformedCall = createTransformedCall(node);
39
+ path.replaceWith(transformedCall);
40
+ transformCount++;
41
+ }
42
+ },
43
+ });
44
+ const output = (0, generator_1.default)(ast, { retainLines: false, comments: true }, source);
45
+ if (options.debug && transformCount > 0) {
46
+ console.log(`[signaltree callable-syntax] transformed ${transformCount} calls`);
47
+ }
48
+ return { code: output.code, transformed: transformCount };
49
+ }
50
+ /**
51
+ * Parses TypeScript/JSX source code into an AST
52
+ */
53
+ function parseSourceCode(source) {
54
+ return (0, parser_1.parse)(source, {
55
+ sourceType: 'module',
56
+ plugins: ['typescript', 'jsx'],
57
+ });
58
+ }
59
+ /**
60
+ * Determines if a call expression should be transformed
61
+ */
62
+ function shouldTransformCallExpression(node, rootIds) {
63
+ // Must be a member expression call (e.g., obj.prop())
64
+ if (!t.isMemberExpression(node.callee))
65
+ return false;
66
+ // Skip getter calls (no arguments)
67
+ if (node.arguments.length === 0)
68
+ return false;
69
+ // Skip if already calling .set or .update
70
+ if (isAlreadyTransformed(node.callee))
71
+ return false;
72
+ // Must be accessing a signal from one of the root identifiers
73
+ return isRootedSignalAccess(node.callee, rootIds);
74
+ }
75
+ /**
76
+ * Checks if the call is already transformed (.set or .update)
77
+ */
78
+ function isAlreadyTransformed(callee) {
79
+ return (t.isIdentifier(callee.property) &&
80
+ (callee.property.name === 'set' || callee.property.name === 'update'));
81
+ }
82
+ /**
83
+ * Creates the transformed call expression with .set or .update
84
+ */
85
+ function createTransformedCall(node) {
86
+ const callee = node.callee;
87
+ const method = determineMethod(node.arguments[0]);
88
+ return t.callExpression(t.memberExpression(callee, t.identifier(method)), node.arguments);
89
+ }
90
+ /**
91
+ * Determines whether to use 'set' or 'update' based on the argument type
92
+ */
93
+ function determineMethod(firstArg) {
94
+ if (t.isFunctionExpression(firstArg) ||
95
+ t.isArrowFunctionExpression(firstArg)) {
96
+ return 'update';
97
+ }
98
+ return 'set';
99
+ }
100
+ /**
101
+ * Checks if the member expression ultimately accesses a signal from a root identifier
102
+ */
103
+ function isRootedSignalAccess(expr, roots) {
104
+ let current = expr;
105
+ // Traverse up the member expression chain to find the root identifier
106
+ while (t.isMemberExpression(current)) {
107
+ if (t.isIdentifier(current.object)) {
108
+ return roots.includes(current.object.name);
109
+ }
110
+ current = current.object;
111
+ }
112
+ return false;
113
+ }
114
+ //# sourceMappingURL=ast-transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-transform.js","sourceRoot":"","sources":["../../../../../packages/callable-syntax/src/lib/ast-transform.ts"],"names":[],"mappings":";;;AAmCA,sCAgCC;;AAnED,yEAAwC;AACxC,0CAAsC;AACtC,uEAAuC;AACvC,wDAAkC;AAgBrB,QAAA,wBAAwB,GAAG,CAAC,MAAM,CAAC,CAAC;AAEjD;;;;;;;;;;;;;GAaG;AACH,SAAgB,aAAa,CAC3B,MAAc,EACd,UAA4B,EAAE;;IAE9B,MAAM,OAAO,GAAG,CAAA,MAAA,OAAO,CAAC,eAAe,0CAAE,MAAM;QAC7C,CAAC,CAAC,OAAO,CAAC,eAAe;QACzB,CAAC,CAAC,gCAAwB,CAAC;IAC7B,MAAM,GAAG,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACpC,IAAI,cAAc,GAAG,CAAC,CAAC;IAEvB,IAAA,kBAAQ,EAAC,GAAG,EAAE;QACZ,cAAc,CAAC,IAAI;YACjB,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;YACtB,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBAAE,OAAO;YAEtC,IAAI,6BAA6B,CAAC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-0,0 +1 @@
1
+ export declare const syntaxTransform: () => string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syntaxTransform = void 0;
4
+ // Deprecated placeholder kept to avoid breaking the initial test; actual exports moved.
5
+ const syntaxTransform = () => 'callable-syntax';
6
+ exports.syntaxTransform = syntaxTransform;
7
+ //# sourceMappingURL=syntax-transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syntax-transform.js","sourceRoot":"","sources":["../../../../../packages/callable-syntax/src/lib/syntax-transform.ts"],"names":[],"mappings":";;;AAAA,wFAAwF;AACjF,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,iBAAiB,CAAC;AAA1C,QAAA,eAAe,mBAA2B"}
@@ -0,0 +1,16 @@
1
+ type Plugin = {
2
+ name: string;
3
+ enforce?: 'pre' | 'post';
4
+ transform?: (code: string, id: string) => {
5
+ code: string;
6
+ map: null;
7
+ } | null;
8
+ };
9
+ export interface SignalTreeVitePluginOptions {
10
+ include?: RegExp;
11
+ exclude?: RegExp;
12
+ rootIdentifiers?: string[];
13
+ debug?: boolean;
14
+ }
15
+ export declare function signalTreeSyntaxTransform(options?: SignalTreeVitePluginOptions): Plugin;
16
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signalTreeSyntaxTransform = signalTreeSyntaxTransform;
4
+ const ast_transform_1 = require("./ast-transform");
5
+ function signalTreeSyntaxTransform(options = {}) {
6
+ var _a, _b;
7
+ const include = (_a = options.include) !== null && _a !== void 0 ? _a : /src\/.*\.(t|j)sx?$/;
8
+ const exclude = (_b = options.exclude) !== null && _b !== void 0 ? _b : /node_modules|\.spec\.|\.test\./;
9
+ return {
10
+ name: 'signaltree-callable-syntax',
11
+ enforce: 'pre',
12
+ transform(code, id) {
13
+ if (!include.test(id) || exclude.test(id))
14
+ return null;
15
+ const result = (0, ast_transform_1.transformCode)(code, {
16
+ rootIdentifiers: options.rootIdentifiers,
17
+ debug: options.debug,
18
+ });
19
+ if (result.transformed === 0)
20
+ return null;
21
+ return { code: result.code, map: null };
22
+ },
23
+ };
24
+ }
25
+ //# sourceMappingURL=vite-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../../../../../packages/callable-syntax/src/lib/vite-plugin.ts"],"names":[],"mappings":";;AAgBA,8DAmBC;AAnCD,mDAAgD;AAgBhD,SAAgB,yBAAyB,CACvC,UAAuC,EAAE;;IAEzC,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,oBAAoB,CAAC;IACxD,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,gCAAgC,CAAC;IAEpE,OAAO;QACL,IAAI,EAAE,4BAA4B;QAClC,OAAO,EAAE,KAAK;QACd,SAAS,CAAC,IAAY,EAAE,EAAU;YAChC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAE,OAAO,IAAI,CAAC;YACvD,MAAM,MAAM,GAAG,IAAA,6BAAa,EAAC,IAAI,EAAE;gBACjC,eAAe,EAAE,OAAO,CAAC,eAAe;gBACxC,KAAK,EAAE,OAAO,CAAC,KAAK;aACrB,CAAC,CAAC;YACH,IAAI,MAAM,CAAC,WAAW,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAC;YAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ interface CompilationLike {
2
+ assets: Record<string, {
3
+ source(): unknown;
4
+ size(): number;
5
+ }>;
6
+ }
7
+ interface CompilerLike {
8
+ hooks: {
9
+ emit: {
10
+ tapAsync(name: string, cb: (compilation: CompilationLike, done: (err?: Error) => void) => void): void;
11
+ };
12
+ };
13
+ }
14
+ export interface SignalTreeWebpackPluginOptions {
15
+ test?: RegExp;
16
+ exclude?: RegExp;
17
+ rootIdentifiers?: string[];
18
+ debug?: boolean;
19
+ }
20
+ export declare class SignalTreeSyntaxWebpackPlugin {
21
+ private readonly options;
22
+ constructor(options?: SignalTreeWebpackPluginOptions);
23
+ apply(compiler: CompilerLike): void;
24
+ }
25
+ export {};
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SignalTreeSyntaxWebpackPlugin = void 0;
4
+ const ast_transform_1 = require("./ast-transform");
5
+ class SignalTreeSyntaxWebpackPlugin {
6
+ constructor(options = {}) {
7
+ this.options = options;
8
+ }
9
+ apply(compiler) {
10
+ var _a, _b;
11
+ const test = (_a = this.options.test) !== null && _a !== void 0 ? _a : /src\/.*\.(t|j)sx?$/;
12
+ const exclude = (_b = this.options.exclude) !== null && _b !== void 0 ? _b : /node_modules|\.spec\.|\.test\./;
13
+ compiler.hooks.emit.tapAsync('SignalTreeSyntaxWebpackPlugin', (compilation, cb) => {
14
+ for (const filename of Object.keys(compilation.assets)) {
15
+ if (!test.test(filename) || exclude.test(filename))
16
+ continue;
17
+ const asset = compilation.assets[filename];
18
+ const raw = asset.source();
19
+ // Handle different source types from webpack assets
20
+ let source;
21
+ if (typeof raw === 'string') {
22
+ source = raw;
23
+ }
24
+ else if (Buffer.isBuffer(raw)) {
25
+ source = raw.toString('utf8');
26
+ }
27
+ else {
28
+ source = String(raw);
29
+ }
30
+ const { code, transformed } = (0, ast_transform_1.transformCode)(source, {
31
+ rootIdentifiers: this.options.rootIdentifiers,
32
+ debug: this.options.debug,
33
+ });
34
+ if (transformed > 0) {
35
+ const updated = code;
36
+ // Webpack 5 source compatibility minimal implementation
37
+ compilation.assets[filename] = {
38
+ source: () => updated,
39
+ size: () => Buffer.byteLength(updated, 'utf8'),
40
+ };
41
+ }
42
+ }
43
+ cb();
44
+ });
45
+ }
46
+ }
47
+ exports.SignalTreeSyntaxWebpackPlugin = SignalTreeSyntaxWebpackPlugin;
48
+ //# sourceMappingURL=webpack-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack-plugin.js","sourceRoot":"","sources":["../../../../../packages/callable-syntax/src/lib/webpack-plugin.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAwBhD,MAAa,6BAA6B;IACxC,YAA6B,UAA0C,EAAE;QAA5C,YAAO,GAAP,OAAO,CAAqC;IAAG,CAAC;IAE7E,KAAK,CAAC,QAAsB;;QAC1B,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,IAAI,mCAAI,oBAAoB,CAAC;QACvD,MAAM,OAAO,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,OAAO,mCAAI,gCAAgC,CAAC;QAEzE,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAC1B,+BAA+B,EAC/B,CAAC,WAA4B,EAAE,EAAyB,EAAE,EAAE;YAC1D,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;gBACvD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;oBAAE,SAAS;gBAC7D,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC3C,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;gBAE3B,oDAAoD;gBACpD,IAAI,MAAc,CAAC;gBACnB,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;oBAC5B,MAAM,GAAG,GAAG,CAAC;gBACf,CAAC;qBAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;oBAChC,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;gBAChC,CAAC;qBA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