Skip to content
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

proposal: template/html: add support for Javascript modules #31600

Closed
odeke-em opened this issue Apr 21, 2019 · 3 comments
Closed

proposal: template/html: add support for Javascript modules #31600

odeke-em opened this issue Apr 21, 2019 · 3 comments

Comments

@odeke-em
Copy link
Member

Coming here from https://go-review.googlesource.com/c/go/+/135417/1#message-7dd5e123817a64371e99231b997ff292794e9e33 in which I suggested we create a corresponding issue for posterity and for detailed conversations/discussions

@tomuta submitted PR #27697 and below are details of the PR

What did you do?

template/html does not properly treat javascript code as javascript when using a <script type="module" tag:

<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
	</head>
	<body>
	<script type='module'>
		1 <= 2
	</script>
</html>

What did you expect to see?

<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
	</head>
	<body>
	<script type='module'>
		1 <= 2
	</script>
</html>

What did you see instead?

<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
	</head>
	<body>
	<script type='module'>
		1 &lt;= 2
	</script>
</html>

See also: https://www.w3.org/TR/html5/semantics-scripting.html#element-attrdef-script-type

@gopherbot gopherbot added this to the Proposal milestone Apr 21, 2019
@odeke-em
Copy link
Member Author

@mikesamuel I see you've given a +1 at https://go-review.googlesource.com/c/go/+/135417/1#message-20591718bc2c308ca766ccac27521a70e769f09a
Could you please comment here with your details to aid in the proposal approval process? Thank you!

@mikesamuel
Copy link
Contributor

@odeke-em From #31327 (comment)

@mikesamuel do you have more context on JS modules differences with normal scripts?

There's no significant difference.
A JS ModuleBody is just a strict mode ScriptBody that can also contain import and export declarations.
So I think we can add "module" to https://golang.org/src/html/template/js.go#L390

func isJSType(mimeType string) bool {
        ...
	switch mimeType {
	case
		"application/ecmascript",
                ...
        }
        ...
}

@tomuta

@odeke-em
Copy link
Member Author

Thanks for linking that already created issue @mikesamuel! I'll close this one since it is a duplicate of #31327

@golang golang locked and limited conversation to collaborators Apr 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants