@jsenv/ast 6.3.4 → 6.3.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/ast",
3
- "version": "6.3.4",
3
+ "version": "6.3.5",
4
4
  "description": "Parse and transform HTML, CSS and JS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -130,9 +130,38 @@ const getJsenvScriptsNode = (htmlAst) => {
130
130
  jsenvScripts = createHtmlNode({
131
131
  tagName: "jsenv-scripts",
132
132
  });
133
- getAsFirstJsModuleInjector(htmlAst, {
134
- anyScript: true,
135
- })(jsenvScripts);
133
+ const headNode = findChild(htmlAst, (node) => node.nodeName === "html")
134
+ .childNodes[0];
135
+ let after = headNode.childNodes[0];
136
+ for (const child of headNode.childNodes) {
137
+ if (child.nodeName === "link") {
138
+ after = child;
139
+ continue;
140
+ }
141
+ if (child.nodeName === "script") {
142
+ const { type } = analyzeScriptNode(child);
143
+ if (type === "js_classic") {
144
+ insertHtmlNodeBefore(jsenvScripts, child);
145
+ return jsenvScripts;
146
+ }
147
+ if (type === "importmap") {
148
+ insertHtmlNodeAfter(jsenvScripts, child);
149
+ return jsenvScripts;
150
+ }
151
+ if (type === "js_module") {
152
+ insertHtmlNodeBefore(jsenvScripts, child);
153
+ return jsenvScripts;
154
+ }
155
+ }
156
+ if (child.nodeName === "meta") {
157
+ after = child;
158
+ }
159
+ }
160
+ if (after) {
161
+ insertHtmlNodeAfter(jsenvScripts, after);
162
+ return jsenvScripts;
163
+ }
164
+ injectHtmlNode(htmlAst, jsenvScripts);
136
165
  return jsenvScripts;
137
166
  };
138
167
  const stringifyParams = (params, prefix = "") => {