-
-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected token. Did you mean {'>'}
or >
?
#143
Comments
Could you paste the complete code of that file? |
This is probably because of the code before it got transformed with a missing brackets. Can you provide the code before it? |
<script>
import { onMount } from "svelte";
import u from "./Helper/utils.js";
import msgbox from "./Components/msgbox.js";
import Tabs from "./Components/tabs.svelte";
import Button from "./Components/Button.svelte";
import InboxTab from "./Main/Inbox.svelte";
import ArchiveTab from "./Main/Archive.svelte";
import HelpTab from "./Main/Help.svelte";
import SettingsTab from "./Main/Settings.svelte";
import DocOutTab from "./Main/DocOut.svelte";
let mainid = "mainid";
let server = "";
let TABS;
let timer = null;
// let RTL = false;
onMount(() => {
u.addPrototypes();
TABS.addtab({
name: "inbox",
description: "$Inbox$",
icon: "gi-save-file", //icons.faFolderOpen
});
TABS.addtab({
name: "docout",
description: "$Docs Out$",
icon: "gi-open-file", //icons.faFilter
});
TABS.addtab({
name: "archive",
description: "$Search Letters$",
icon: "gi-search", //icons.faFilter
});
TABS.addtab({
name: "settings",
description: "$Settings$",
icon: "gi-cog", // icons.faCog
});
TABS.addtab({
name: "help",
description: "$Help$",
icon: "gi-question-sign",
});
setTimeout(() => {
// kludge to get the server for fetch
u.GET("/api/getuser").then((r) => (server = r));
// server = window.ServerURL;
u.GET("/api/inbox.getsettings").then((data) => {
if (data.Color) {
u.SetTheme(data.Color);
}
if (data.Language == "fa") {
document.body.dir = "rtl";
// document.documentElement.style.setProperty("--tblAlign", "right");
}
});
TABS.setInitial();
}, 0);
// Heartbeat for auto update
timer = setInterval(() => {
u.GET("/api/getuser").catch(() => {
clearInterval(timer);
msgbox.Ok("$Connection Failed!$", "", () => window.location.reload(true));
});
}, 10 * 1000);
});
// register all tabs to be created here for Tab component
function createTab(tabname, id, props) {
var tab = null;
switch (tabname) {
case "inbox":
tab = new InboxTab({
target: document.getElementById(id),
});
break;
case "help":
tab = new HelpTab({
target: document.getElementById(id),
});
break;
case "archive":
tab = new ArchiveTab({
target: document.getElementById(id),
});
break;
case "settings":
tab = new SettingsTab({
target: document.getElementById(id),
});
break;
case "docout":
tab = new DocOutTab({
target: document.getElementById(id),
});
break;
}
return tab;
}
// function configeditor() {
// // console.log("here");
// }
</script> |
Pasting the given code into an |
I'm not an expert, so you will have to tell me what/where to look for. |
Can you also provide the markup and the skyle tag? |
I found the culprit: <svelte:head>
<link rel="stylesheet" href="/lib/jodit.es2018.min.css" />
<script src="/lib/jodit.es2018.min.js">
</script>
</svelte:head> It's the |
This is another case where our regex-parser fails. Maybe we should switch to using a html parser instead like svelte2tsx does already - but we need to check if that handles the case correctly or also fails. There we can check if the script/styles have a parent, and if not, ignore it. Maybe we can share the logic and extract it as a util from |
I've opened another request regarding the optimization of the vs code extension size on disk (currently 150mb). |
I saw this and did not have time to look into this yet. It's weekend and we all do this in our free time. Also please keep issues separate which don't have anything to do with each other. |
Thanks. |
@dummdidumm interested in picking up this first issue. is the idea that we should use htmlxparser.ts instead of the regex parsing? are there any other alternatives you haven't discussed? |
Yes, the idea would be to make the An alternative would be to somehow enhance the regex to only look for top level scripts/styles, but I feel this gets too complicated for a regex then. |
ok i'm going to err on the side of duplicating it. clean code is overrated :) |
i have set up a test for this inside of https://github.com/sveltejs/language-tools/blob/master/packages/language-server/test/lib/documents/utils.test.ts but I am not sure it is the right way to test it: it('ignores script tag in svelte:head', () => {
// https://github.com/sveltejs/language-tools/issues/143#issuecomment-636422045
const text = `
<svelte:head>
<link rel="stylesheet" href="/lib/jodit.es2018.min.css" />
<script src="/lib/jodit.es2018.min.js">
</script>
</svelte:head>
<p>jo</p>
<script>top level script</script>
<h1>Hello, world!</h1>
<style>.bla {}</style>
`
assert.deepStrictEqual(extractTag(text, 'script'), {
// ????
});
}) it doesnt give the Unexpected token error but it does match the wrong |
for whoever sees this in future - i ended up completely not duplicating it at all - the requirements for |
The problem still exists in |
Turns out it's not only a problem with // ....
<sveltehead>
<link rel="stylesheet" href="/lib/jodit.es2018.min.css" />
<script src=""/lib/jodit.es2018.min.js""> // <<<-- two `"` each, syntax error
</script>
</sveltehead> |
End of attr and attrVal are the same even if they have quotes surrounding it -> needs an extra check for "last character is a quote" Fixes sveltejs#143
End of attr and attrVal are the same even if they have quotes surrounding it -> needs an extra check for "last character is a quote" Fixes #143
The problem still exists in |
I cannot reproduce the bug with the latest version, given your code snippet with |
@dummdidumm nice work/investigations. sounds like we should use https://babeljs.io/docs/en/babel-parser instead? |
Will that parse a html string into a correct AST? Isn't that for js(x)/ts(x) only? Basically we need some html parser like Or someone finds a regex that works and we revert to using that, but it is unlikely we find something without massive workarounds. |
we dont need it to be exactly correct 🤷 also i want to go back to what @mgholam said. why cant we use svelte's own parse function? guarantees absolute parity esp if we only care about top level tags |
We can do that as soon as sveltejs/svelte#4818 is dealt with. Maybe use acorn/acorn-loose in the meantime? |
i dont know enough to make a call here. i'm not confident that using the svelte parse function is the best choice for this usecase. does the svelte parser do everything we need for |
|
Can you make the first script "win" and be the top level script? (as a thought...) |
Yes this could be a good quickfix in the meantime. I also have another idea, will have to test it out. |
All script tags, no matter at what level, are listed within the root children. To get the top level scripts, filter out all those that are part of children's children. Those have another type ('Element' with name 'script'). Fixes sveltejs#143
All script tags, no matter at what level, are listed within the root children. To get the top level scripts, filter out all those that are part of children's children. Those have another type ('Element' with name 'script'). Fixes #143
Third time's a charm - let's hope it's fixed with the next deployment in about 12 hours. I created a separate issue for the self-closing-tag-bug (#194) |
Woo Hoo! Thanks! |
Regression if the script block is commented :
|
Cannot reproduce with your snippet. |
|
Else script is not identified as such later #143
Fix available soon. |
Still exists in <script >
import { onMount } from "svelte";
// } // <- error here
</script>
<svelte:head>
<!-- <script src="/lib/jodit.es2018.min.js">
</script> -->
</svelte:head> |
I have encountered this issue while i was developing my code in VScode editor.And,there is nothing wrong with the code and there are no problems showing in the terminal and Program is also executing very well.And then i just restarted my vscode editor ,everything got resolved I mean the error which was quoted in the question. |
Probably not related. The codebase has changed a lot since then. If you have a |
For anyone facing this issue: I uninstalled |
Even I am facing the same issue: `
} export default SortCards; |
I tried this, but doesn't worked for me |
Your code snippet is JSX code, Svelte does not support JSX. |
Describe the bug
On a perfectly good
app.svelte
file I'm getting the above.System (please complete the following information):
The text was updated successfully, but these errors were encountered: