Skip to content

Commit 2887ff0

Browse files
committed
try to fix
1 parent e1a4d15 commit 2887ff0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/parser/index.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,16 @@ export function parseForESLint(code: string, options?: any): ParseResult {
118118

119119
if (
120120
parserOptions.filePath &&
121-
(parserOptions.filePath.endsWith(".svelte.js") ||
122-
parserOptions.filePath.endsWith(".svelte.ts"))
121+
!parserOptions.filePath.endsWith(".svelte") &&
122+
// If no `filePath` is set in ESLint, "<input>" will be specified.
123+
parserOptions.filePath !== "<input>"
123124
) {
124-
const svelteParseContext =
125-
resolveSvelteParseContextForSvelteScript(svelteConfig);
126-
return parseAsScript(code, parserOptions, svelteParseContext);
125+
const trimmed = code.trim();
126+
if (!trimmed.startsWith("<") && !trimmed.endsWith(">")) {
127+
const svelteParseContext =
128+
resolveSvelteParseContextForSvelteScript(svelteConfig);
129+
return parseAsScript(code, parserOptions, svelteParseContext);
130+
}
127131
}
128132

129133
return parseAsSvelte(code, svelteConfig, parserOptions);

0 commit comments

Comments
 (0)