Skip to content

Commit

Permalink
Merge pull request #443 from jsenv/script_jsenv_type_attribute
Browse files Browse the repository at this point in the history
Script jsenv type attribute
  • Loading branch information
dmail authored Nov 27, 2024
2 parents 6784321 + 3fc2d0e commit b814101
Show file tree
Hide file tree
Showing 28 changed files with 139 additions and 103 deletions.
48 changes: 27 additions & 21 deletions dist/jsenv_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -16646,6 +16646,31 @@ const jsenvPluginHtmlReferenceAnalysis = ({
actions.push(async () => {
const inlineUrlInfo = inlineReference.urlInfo;
await inlineUrlInfo.cook();
const typeAttribute = getHtmlNodeAttribute(node, "type");
if (expectedType === "js_classic") {
if (
typeAttribute !== undefined &&
typeAttribute !== "text/javascript"
) {
// 1. <script type="jsx"> becomes <script>
mutations.push(() => {
setHtmlNodeAttributes(node, {
"type": undefined,
"original-type": typeAttribute,
});
});
}
} else if (expectedType === "js_module") {
// 2. <script type="module/jsx"> becomes <script type="module">
if (typeAttribute !== "module") {
mutations.push(() => {
setHtmlNodeAttributes(node, {
"type": "module",
"original-type": typeAttribute,
});
});
}
}
mutations.push(() => {
if (hotAccept) {
removeHtmlNodeText(node);
Expand Down Expand Up @@ -16710,7 +16735,7 @@ const jsenvPluginHtmlReferenceAnalysis = ({
}
: null,
script: (scriptNode) => {
const { type, subtype, contentType, extension } =
const { type, subtype, contentType } =
analyzeScriptNode(scriptNode);
if (type === "text") {
// ignore <script type="whatever">foobar</script>
Expand Down Expand Up @@ -16849,31 +16874,12 @@ const jsenvPluginHtmlReferenceAnalysis = ({
) {
return;
}

const inlineRef = visitTextContent(scriptNode, {
visitTextContent(scriptNode, {
type: "script",
subtype,
expectedType: type,
contentType,
});
if (inlineRef) {
// 1. <script type="jsx"> becomes <script>
if (type === "js_classic" && extension !== ".js") {
mutations.push(() => {
setHtmlNodeAttributes(scriptNode, {
type: undefined,
});
});
}
// 2. <script type="module/jsx"> becomes <script type="module">
if (type === "js_module" && extension !== ".js") {
mutations.push(() => {
setHtmlNodeAttributes(scriptNode, {
type: "module",
});
});
}
}
},
a: (aNode) => {
visitHref(aNode, {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/core",
"version": "39.6.0",
"version": "39.7.0",
"description": "Tool to develop, test and build js projects",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -69,17 +69,17 @@
"dependencies": {
"@financial-times/polyfill-useragent-normaliser": "1.10.2",
"@jsenv/abort": "4.3.0",
"@jsenv/ast": "6.3.7",
"@jsenv/ast": "6.4.0",
"@jsenv/filesystem": "4.10.13",
"@jsenv/humanize": "1.2.8",
"@jsenv/importmap": "1.2.1",
"@jsenv/integrity": "0.0.2",
"@jsenv/js-module-fallback": "1.3.51",
"@jsenv/js-module-fallback": "1.3.52",
"@jsenv/node-esm-resolution": "1.0.6",
"@jsenv/plugin-bundling": "2.7.19",
"@jsenv/plugin-minification": "1.5.11",
"@jsenv/plugin-supervisor": "1.5.30",
"@jsenv/plugin-transpilation": "1.4.86",
"@jsenv/plugin-supervisor": "1.5.31",
"@jsenv/plugin-transpilation": "1.4.87",
"@jsenv/runtime-compat": "1.3.1",
"@jsenv/server": "15.3.3",
"@jsenv/sourcemap": "1.2.27",
Expand Down
4 changes: 2 additions & 2 deletions packages/independent/md-up/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/md-up",
"version": "0.0.9",
"version": "0.0.10",
"license": "MIT",
"private": true,
"repository": {
Expand All @@ -26,6 +26,6 @@
"marked": "15.0.2",
"@jsenv/filesystem": "4.10.13",
"@jsenv/urls": "2.5.4",
"@jsenv/ast": "6.3.7"
"@jsenv/ast": "6.4.0"
}
}
4 changes: 2 additions & 2 deletions packages/independent/snapshot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/snapshot",
"version": "2.11.21",
"version": "2.11.22",
"description": "Snapshot testing",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -31,7 +31,7 @@
],
"dependencies": {
"@jsenv/assert": "4.4.2",
"@jsenv/ast": "6.3.7",
"@jsenv/ast": "6.4.0",
"@jsenv/exception": "1.1.3",
"@jsenv/humanize": "1.2.8",
"@jsenv/filesystem": "4.10.13",
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/ast/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/ast",
"version": "6.3.7",
"version": "6.4.0",
"description": "Parse and transform HTML, CSS and JS",
"license": "MIT",
"repository": {
Expand Down
5 changes: 4 additions & 1 deletion packages/internal/ast/src/html/html_analysis.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { getHtmlNodeAttribute } from "./html_node_attributes.js";

export const analyzeScriptNode = (scriptNode) => {
const typeAttribute = getHtmlNodeAttribute(scriptNode, "type");
const typeAttribute =
getHtmlNodeAttribute(scriptNode, "jsenv-type") ||
getHtmlNodeAttribute(scriptNode, "original-type") ||
getHtmlNodeAttribute(scriptNode, "type");
if (typeAttribute === undefined || typeAttribute === "text/javascript") {
return {
type: "js_classic",
Expand Down
4 changes: 2 additions & 2 deletions packages/internal/js-module-fallback/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/js-module-fallback",
"version": "1.3.51",
"version": "1.3.52",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -31,7 +31,7 @@
"@babel/plugin-transform-modules-umd": "7.25.9",
"@babel/plugin-transform-modules-systemjs": "7.25.9",
"babel-plugin-transform-async-to-promises": "0.8.18",
"@jsenv/ast": "6.3.7",
"@jsenv/ast": "6.4.0",
"@jsenv/sourcemap": "1.2.27",
"@jsenv/urls": "2.5.4"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/internal/plugin-supervisor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/plugin-supervisor",
"version": "1.5.30",
"version": "1.5.31",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -26,7 +26,7 @@
"/dist/"
],
"dependencies": {
"@jsenv/ast": "6.3.7",
"@jsenv/ast": "6.4.0",
"@jsenv/urls": "2.5.4",
"@jsenv/sourcemap": "1.2.27",
"launch-editor": "2.9.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/internal/plugin-transpilation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/plugin-transpilation",
"version": "1.4.86",
"version": "1.4.87",
"description": "TODO",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -51,8 +51,8 @@
"@babel/plugin-transform-template-literals": "7.25.9",
"@babel/plugin-transform-typeof-symbol": "7.25.9",
"@babel/plugin-transform-unicode-regex": "7.25.9",
"@jsenv/ast": "6.3.7",
"@jsenv/js-module-fallback": "1.3.51",
"@jsenv/ast": "6.4.0",
"@jsenv/js-module-fallback": "1.3.52",
"@jsenv/runtime-compat": "1.3.1",
"babel-plugin-transform-async-to-promises": "0.8.18",
"construct-style-sheets-polyfill": "3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/related/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/cli",
"version": "0.2.15",
"version": "0.2.16",
"description": "Command Line Interface for jsenv",
"license": "MIT",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/related/cli/template-node-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
},
"devDependencies": {
"@jsenv/assert": "4.4.2",
"@jsenv/core": "39.6.0",
"@jsenv/core": "39.7.0",
"@jsenv/eslint-config-relax": "1.3.4",
"@jsenv/test": "3.5.28",
"@jsenv/test": "3.5.29",
"eslint": "9.15.0",
"prettier": "3.3.3"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/related/cli/template-web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
"@babel/plugin-syntax-import-attributes": "7.26.0",
"@jsenv/custom-elements-redefine": "0.0.1",
"@jsenv/assert": "4.4.2",
"@jsenv/core": "39.6.0",
"@jsenv/core": "39.7.0",
"@jsenv/plugin-bundling": "2.7.19",
"@jsenv/plugin-minification": "1.5.11",
"@jsenv/eslint-config-relax": "1.3.4",
"@jsenv/test": "3.5.28",
"@jsenv/test": "3.5.29",
"eslint": "9.15.0",
"open": "10.1.0",
"@playwright/browser-chromium": "1.49.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/related/cli/template-web-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
"@babel/plugin-syntax-import-attributes": "7.26.0",
"@babel/plugin-transform-react-jsx": "7.25.9",
"@jsenv/assert": "4.4.2",
"@jsenv/core": "39.6.0",
"@jsenv/plugin-preact": "1.6.28",
"@jsenv/core": "39.7.0",
"@jsenv/plugin-preact": "1.6.29",
"@jsenv/plugin-bundling": "2.7.19",
"@jsenv/plugin-minification": "1.5.11",
"@jsenv/eslint-config-relax": "1.3.4",
"@jsenv/test": "3.5.28",
"@jsenv/test": "3.5.29",
"eslint": "9.15.0",
"open": "10.1.0",
"@playwright/browser-chromium": "1.49.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/related/cli/template-web-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"@babel/plugin-syntax-import-attributes": "7.26.0",
"@babel/plugin-transform-react-jsx": "7.25.9",
"@jsenv/assert": "4.4.2",
"@jsenv/core": "39.6.0",
"@jsenv/plugin-react": "1.5.47",
"@jsenv/core": "39.7.0",
"@jsenv/plugin-react": "1.5.48",
"@jsenv/plugin-bundling": "2.7.19",
"@jsenv/plugin-minification": "1.5.11",
"@jsenv/eslint-config-relax": "1.3.4",
"@jsenv/test": "3.5.28",
"@jsenv/test": "3.5.29",
"eslint": "9.15.0",
"open": "10.1.0",
"@playwright/browser-chromium": "1.49.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/related/cli/template-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"devDependencies": {
"@babel/plugin-syntax-import-attributes": "7.26.0",
"@jsenv/assert": "4.4.2",
"@jsenv/core": "39.6.0",
"@jsenv/core": "39.7.0",
"@jsenv/eslint-config-relax": "1.3.4",
"@jsenv/plugin-bundling": "2.7.19",
"@jsenv/plugin-minification": "1.5.11",
"@jsenv/test": "3.5.28",
"@jsenv/test": "3.5.29",
"eslint": "9.15.0",
"open": "10.1.0",
"@playwright/browser-chromium": "1.49.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/related/plugin-as-js-classic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/plugin-as-js-classic",
"version": "1.5.63",
"version": "1.5.64",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -22,7 +22,7 @@
],
"dependencies": {
"@jsenv/urls": "2.5.4",
"@jsenv/js-module-fallback": "1.3.51",
"@jsenv/js-module-fallback": "1.3.52",
"@jsenv/plugin-bundling": "2.7.19"
}
}
4 changes: 2 additions & 2 deletions packages/related/plugin-preact/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/plugin-preact",
"version": "1.6.28",
"version": "1.6.29",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -24,7 +24,7 @@
"babel-plugin-transform-hook-names": "1.0.2",
"@babel/plugin-transform-react-jsx": "7.25.9",
"@babel/plugin-transform-react-jsx-development": "7.25.9",
"@jsenv/ast": "6.3.7",
"@jsenv/ast": "6.4.0",
"@jsenv/sourcemap": "1.2.27",
"@jsenv/url-meta": "8.5.2",
"@prefresh/babel-plugin": "0.5.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>Title</title>
<meta charset="utf-8">
<link rel="icon" href="data:,">
<script type="importmap">
{
"imports": {
Expand All @@ -21,7 +22,7 @@
window.resolveResultPromise = resolve;
});
</script>
<script type="module">import { render } from "/js/preact.module.js";
<script type="module" jsenv-type="module/jsx">import { render } from "/js/preact.module.js";
import { useEffect } from "/js/hooks.module.js";

// eslint-disable-next-line no-unused-vars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>Title</title>
<meta charset="utf-8">
<link rel="icon" href="data:,">
<script>
;(function() {
var __versionMappings__ = {
Expand Down Expand Up @@ -475,7 +476,7 @@
window.resolveResultPromise = resolve;
});
</script>
<script>System.register([__v__("/js/preact.module.nomodule.js"), __v__("/js/hooks.module.nomodule.js"), __v__("/js/jsxRuntime.module.nomodule.js")], function (_export, _context) {
<script jsenv-type="module/jsx">System.register([__v__("/js/preact.module.nomodule.js"), __v__("/js/hooks.module.nomodule.js"), __v__("/js/jsxRuntime.module.nomodule.js")], function (_export, _context) {
"use strict";

var render, useEffect, _jsx, App;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>Title</title>
<meta charset="utf-8">
<link rel="icon" href="data:,">
</head>
<body>
<jsenv-scripts>
Expand All @@ -25,11 +26,11 @@
"scriptInfos": [
{
"type": "js_classic",
"src": "/main.html@L10C5-L14C14.js"
"src": "/main.html@L11C5-L15C14.js"
},
{
"type": "js_module",
"src": "/main.html@L15C5-L37C14.js"
"src": "/main.html@L16C5-L38C14.jsx"
}
]
});
Expand All @@ -53,11 +54,11 @@


<div id="app"></div>
<script jsenv-cooked-by="jsenv:supervisor" content-indented="" inlined-from-src="/main.html@L10C5-L14C14.js">
window.__supervisor__.superviseScript("/main.html@L10C5-L14C14.js");
<script jsenv-cooked-by="jsenv:supervisor" content-indented="" inlined-from-src="/main.html@L11C5-L15C14.js">
window.__supervisor__.superviseScript("/main.html@L11C5-L15C14.js");
</script>
<script type="module" jsenv-cooked-by="jsenv:supervisor" content-indented="" inlined-from-src="/main.html@L15C5-L37C14.js">
window.__supervisor__.superviseScriptTypeModule("/main.html@L15C5-L37C14.js", (url) => import(url));
<script type="module" jsenv-type="module/jsx" jsenv-cooked-by="jsenv:supervisor" content-indented="" inlined-from-src="/main.html@L16C5-L38C14.jsx">
window.__supervisor__.superviseScriptTypeModule("/main.html@L16C5-L38C14.jsx", (url) => import(url));
</script>
</body>
</html>
Loading

0 comments on commit b814101

Please sign in to comment.