@timber-js/app 0.2.0-alpha.100 → 0.2.0-alpha.101
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/_chunks/{actions-CQ8Z8VGL.js → actions-BsfxK6yu.js} +2 -2
- package/dist/_chunks/{actions-CQ8Z8VGL.js.map → actions-BsfxK6yu.js.map} +1 -1
- package/dist/_chunks/{chunk-BYIpzuS7.js → chunk-Cfpv9whK.js} +1 -8
- package/dist/_chunks/{define-CfBPoJb0.js → define-k32T6NL2.js} +2 -2
- package/dist/_chunks/{define-CfBPoJb0.js.map → define-k32T6NL2.js.map} +1 -1
- package/dist/_chunks/{navigation-root-BCYczjml.js → navigation-root-yx917rG0.js} +2 -2
- package/dist/_chunks/{navigation-root-BCYczjml.js.map → navigation-root-yx917rG0.js.map} +1 -1
- package/dist/_chunks/{use-segment-params-BkpKAQ7D.js → use-segment-params-DlsOX1YS.js} +2 -2
- package/dist/_chunks/{use-segment-params-BkpKAQ7D.js.map → use-segment-params-DlsOX1YS.js.map} +1 -1
- package/dist/client/index.js +4 -4
- package/dist/client/internal.d.ts +1 -1
- package/dist/client/internal.d.ts.map +1 -1
- package/dist/client/internal.js +3 -3
- package/dist/fonts/ast.d.ts +98 -6
- package/dist/fonts/ast.d.ts.map +1 -1
- package/dist/fonts/local.d.ts +1 -1
- package/dist/fonts/transform.d.ts +15 -1
- package/dist/fonts/transform.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1481 -11536
- package/dist/index.js.map +1 -1
- package/dist/plugins/dev-server.d.ts.map +1 -1
- package/dist/plugins/routing.d.ts.map +1 -1
- package/dist/plugins/static-build.d.ts +2 -23
- package/dist/plugins/static-build.d.ts.map +1 -1
- package/dist/segment-params/index.js +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/internal.js +1 -1
- package/package.json +2 -1
- package/src/client/internal.ts +1 -1
- package/src/fonts/ast.ts +488 -16
- package/src/fonts/local.ts +1 -1
- package/src/fonts/transform.ts +147 -236
- package/src/index.ts +14 -2
- package/src/plugins/dev-server.ts +8 -9
- package/src/plugins/routing.ts +1 -12
- package/src/plugins/static-build.ts +3 -83
- package/dist/plugins/server-action-exports.d.ts +0 -26
- package/dist/plugins/server-action-exports.d.ts.map +0 -1
- package/dist/routing/status-file-lint.d.ts +0 -34
- package/dist/routing/status-file-lint.d.ts.map +0 -1
- package/dist/utils/directive-parser.d.ts +0 -28
- package/dist/utils/directive-parser.d.ts.map +0 -1
- package/src/plugins/server-action-exports.ts +0 -220
- package/src/routing/status-file-lint.ts +0 -115
- package/src/utils/directive-parser.ts +0 -140
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AST-based directive detection for 'use client' and 'use server'.
|
|
3
|
-
*
|
|
4
|
-
* Uses acorn to parse source code and detect directives properly,
|
|
5
|
-
* avoiding false positives from regex matching inside string literals,
|
|
6
|
-
* comments, or template expressions.
|
|
7
|
-
*
|
|
8
|
-
* @module
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { Parser } from 'acorn';
|
|
12
|
-
import acornJsx from 'acorn-jsx';
|
|
13
|
-
|
|
14
|
-
// acorn parser with JSX support
|
|
15
|
-
const jsxParser = Parser.extend(acornJsx());
|
|
16
|
-
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
// Types
|
|
19
|
-
// ---------------------------------------------------------------------------
|
|
20
|
-
|
|
21
|
-
export interface FileDirective {
|
|
22
|
-
/** The directive value, e.g. 'use client', 'use server' */
|
|
23
|
-
directive: string;
|
|
24
|
-
/** 1-based line number where the directive appears */
|
|
25
|
-
line: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// ---------------------------------------------------------------------------
|
|
29
|
-
// File-level directive detection
|
|
30
|
-
// ---------------------------------------------------------------------------
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Detect a file-level directive ('use client', 'use server', etc.).
|
|
34
|
-
*
|
|
35
|
-
* Per the ECMAScript spec, directives are string literal expression
|
|
36
|
-
* statements at the start of a program body (before any non-directive
|
|
37
|
-
* statements). This function checks the AST `Program.body` for
|
|
38
|
-
* `ExpressionStatement` nodes whose expression is a `Literal` string
|
|
39
|
-
* matching a known directive.
|
|
40
|
-
*
|
|
41
|
-
* Returns the first matching directive, or null if none found.
|
|
42
|
-
*/
|
|
43
|
-
export function detectFileDirective(
|
|
44
|
-
code: string,
|
|
45
|
-
directives: string[] = ['use client', 'use server']
|
|
46
|
-
): FileDirective | null {
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
-
let ast: any;
|
|
49
|
-
try {
|
|
50
|
-
ast = jsxParser.parse(code, {
|
|
51
|
-
ecmaVersion: 'latest',
|
|
52
|
-
sourceType: 'module',
|
|
53
|
-
locations: true,
|
|
54
|
-
});
|
|
55
|
-
} catch {
|
|
56
|
-
// If the file fails to parse (e.g. TypeScript syntax), fall back to
|
|
57
|
-
// a safe line-by-line check that only considers lines before any
|
|
58
|
-
// non-comment, non-whitespace, non-directive content.
|
|
59
|
-
return detectFileDirectiveFallback(code, directives);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
for (const node of ast.body) {
|
|
63
|
-
if (
|
|
64
|
-
node.type === 'ExpressionStatement' &&
|
|
65
|
-
node.expression.type === 'Literal' &&
|
|
66
|
-
typeof node.expression.value === 'string'
|
|
67
|
-
) {
|
|
68
|
-
if (directives.includes(node.expression.value)) {
|
|
69
|
-
return {
|
|
70
|
-
directive: node.expression.value,
|
|
71
|
-
line: node.loc.start.line,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
// Directives must appear before any non-directive statements
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Fallback for TypeScript files that acorn cannot parse.
|
|
85
|
-
*
|
|
86
|
-
* Scans lines from the top of the file. Skips blank lines and comments.
|
|
87
|
-
* Checks if the first real statement is a directive string literal.
|
|
88
|
-
*/
|
|
89
|
-
function detectFileDirectiveFallback(code: string, directives: string[]): FileDirective | null {
|
|
90
|
-
const lines = code.split('\n');
|
|
91
|
-
let inBlockComment = false;
|
|
92
|
-
|
|
93
|
-
for (let i = 0; i < lines.length; i++) {
|
|
94
|
-
let line = lines[i].trim();
|
|
95
|
-
|
|
96
|
-
// Handle block comments
|
|
97
|
-
if (inBlockComment) {
|
|
98
|
-
const endIdx = line.indexOf('*/');
|
|
99
|
-
if (endIdx === -1) continue;
|
|
100
|
-
line = line.slice(endIdx + 2).trim();
|
|
101
|
-
inBlockComment = false;
|
|
102
|
-
if (!line) continue;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Skip blank lines
|
|
106
|
-
if (!line) continue;
|
|
107
|
-
|
|
108
|
-
// Skip line comments
|
|
109
|
-
if (line.startsWith('//')) continue;
|
|
110
|
-
|
|
111
|
-
// Skip block comment start
|
|
112
|
-
if (line.startsWith('/*')) {
|
|
113
|
-
const endIdx = line.indexOf('*/', 2);
|
|
114
|
-
if (endIdx === -1) {
|
|
115
|
-
inBlockComment = true;
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
line = line.slice(endIdx + 2).trim();
|
|
119
|
-
if (!line) continue;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Check for directive
|
|
123
|
-
for (const dir of directives) {
|
|
124
|
-
// Match 'directive' or "directive" optionally followed by ;
|
|
125
|
-
if (
|
|
126
|
-
line === `'${dir}'` ||
|
|
127
|
-
line === `'${dir}';` ||
|
|
128
|
-
line === `"${dir}"` ||
|
|
129
|
-
line === `"${dir}";`
|
|
130
|
-
) {
|
|
131
|
-
return { directive: dir, line: i + 1 };
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// First non-comment, non-blank line is not a directive — stop
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return null;
|
|
140
|
-
}
|