@astrojs/compiler 0.15.2-pre.0 → 0.16.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @astrojs/compiler
2
2
 
3
+ ## 0.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 470efc0: Adds component metadata to the TransformResult
8
+
9
+ ### Patch Changes
10
+
11
+ - c104d4f: Fix #418: duplicate text when only text
12
+
13
+ ## 0.15.2
14
+
15
+ ### Patch Changes
16
+
17
+ - f951822: Fix wasm `parse` to save attribute namespace
18
+ - 5221e09: Fix serialize spread attribute
19
+
3
20
  ## 0.15.1
4
21
 
5
22
  ### Patch Changes
package/LICENSE ADDED
@@ -0,0 +1,53 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 [Astro contributors](https://github.com/withastro/compiler/graphs/contributors)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ """
24
+ This license applies to parts of the `internal/` subdirectory originating from
25
+ the https://cs.opensource.google/go/x/net/+/master:html/ repository:
26
+
27
+ Copyright (c) 2009 The Go Authors. All rights reserved.
28
+
29
+ Redistribution and use in source and binary forms, with or without
30
+ modification, are permitted provided that the following conditions are
31
+ met:
32
+
33
+ * Redistributions of source code must retain the above copyright
34
+ notice, this list of conditions and the following disclaimer.
35
+ * Redistributions in binary form must reproduce the above
36
+ copyright notice, this list of conditions and the following disclaimer
37
+ in the documentation and/or other materials provided with the
38
+ distribution.
39
+ * Neither the name of Google Inc. nor the names of its
40
+ contributors may be used to endorse or promote products derived from
41
+ this software without specific prior written permission.
42
+
43
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/astro.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -5,10 +5,7 @@
5
5
  "type": "module",
6
6
  "bugs": "https://github.com/withastro/compiler/issues",
7
7
  "homepage": "https://astro.build",
8
- "version": "0.15.2-pre.0",
9
- "scripts": {
10
- "build": "tsc -p ."
11
- },
8
+ "version": "0.16.0",
12
9
  "main": "./node/index.js",
13
10
  "types": "./node",
14
11
  "repository": {
@@ -29,10 +26,6 @@
29
26
  "./astro.wasm": "./astro.wasm",
30
27
  "./types": "./types.d.ts"
31
28
  },
32
- "dependencies": {
33
- "tsm": "^2.2.1",
34
- "uvu": "^0.5.3"
35
- },
36
29
  "devDependencies": {
37
30
  "@types/node": "^16.4.12",
38
31
  "@types/sass": "^1.43.1",
@@ -40,5 +33,8 @@
40
33
  },
41
34
  "volta": {
42
35
  "node": "16.6.2"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc -p ."
43
39
  }
44
- }
40
+ }
@@ -1,4 +0,0 @@
1
- import type * as types from '../shared/types';
2
- export declare const transform: typeof types.transform;
3
- export declare const parse: typeof types.parse;
4
- export declare const initialize: typeof types.initialize;
package/browser/index.js DELETED
@@ -1,55 +0,0 @@
1
- import Go from './wasm_exec.js';
2
- export const transform = (input, options) => {
3
- return ensureServiceIsRunning().transform(input, options);
4
- };
5
- export const parse = (input, options) => {
6
- return ensureServiceIsRunning().parse(input, options);
7
- };
8
- let initializePromise;
9
- let longLivedService;
10
- export const initialize = async (options) => {
11
- let wasmURL = options.wasmURL;
12
- if (!wasmURL)
13
- throw new Error('Must provide the "wasmURL" option');
14
- wasmURL += '';
15
- if (!initializePromise) {
16
- initializePromise = startRunningService(wasmURL).catch((err) => {
17
- // Let the caller try again if this fails.
18
- initializePromise = void 0;
19
- // But still, throw the error back up the caller.
20
- throw err;
21
- });
22
- }
23
- longLivedService = longLivedService || (await initializePromise);
24
- };
25
- let ensureServiceIsRunning = () => {
26
- if (!initializePromise)
27
- throw new Error('You need to call "initialize" before calling this');
28
- if (!longLivedService)
29
- throw new Error('You need to wait for the promise returned from "initialize" to be resolved before calling this');
30
- return longLivedService;
31
- };
32
- const instantiateWASM = async (wasmURL, importObject) => {
33
- let response = undefined;
34
- if (WebAssembly.instantiateStreaming) {
35
- response = await WebAssembly.instantiateStreaming(fetch(wasmURL), importObject);
36
- }
37
- else {
38
- const fetchAndInstantiateTask = async () => {
39
- const wasmArrayBuffer = await fetch(wasmURL).then((res) => res.arrayBuffer());
40
- return WebAssembly.instantiate(wasmArrayBuffer, importObject);
41
- };
42
- response = await fetchAndInstantiateTask();
43
- }
44
- return response;
45
- };
46
- const startRunningService = async (wasmURL) => {
47
- const go = new Go();
48
- const wasm = await instantiateWASM(wasmURL, go.importObject);
49
- go.run(wasm.instance);
50
- const service = globalThis['@astrojs/compiler'];
51
- return {
52
- transform: (input, options) => new Promise((resolve) => resolve(service.transform(input, options || {}))),
53
- parse: (input, options) => new Promise((resolve) => resolve(service.parse(input, options || {}))).then((result) => ({ ...result, ast: JSON.parse(result.ast) })),
54
- };
55
- };
@@ -1,25 +0,0 @@
1
- import { Node, ParentNode, RootNode, ElementNode, CustomElementNode, ComponentNode, FragmentNode, LiteralNode, TagLikeNode, ExpressionNode, TextNode, CommentNode, DoctypeNode, FrontmatterNode } from '../shared/ast';
2
- export interface Visitor {
3
- (node: Node, parent?: ParentNode, index?: number): void | Promise<void>;
4
- }
5
- export declare const is: {
6
- parent(node: Node): node is ParentNode;
7
- literal(node: Node): node is LiteralNode;
8
- tag(node: Node): node is TagLikeNode;
9
- whitespace(node: Node): node is TextNode;
10
- root: (node: Node) => node is RootNode;
11
- element: (node: Node) => node is ElementNode;
12
- customElement: (node: Node) => node is CustomElementNode;
13
- component: (node: Node) => node is ComponentNode;
14
- fragment: (node: Node) => node is FragmentNode;
15
- expression: (node: Node) => node is ExpressionNode;
16
- text: (node: Node) => node is TextNode;
17
- doctype: (node: Node) => node is DoctypeNode;
18
- comment: (node: Node) => node is CommentNode;
19
- frontmatter: (node: Node) => node is FrontmatterNode;
20
- };
21
- export declare function walk(node: ParentNode, callback: Visitor): void;
22
- export interface SerializeOtions {
23
- selfClose: boolean;
24
- }
25
- export declare function serialize(root: Node, opts?: SerializeOtions): string;
package/browser/utils.js DELETED
@@ -1,116 +0,0 @@
1
- function guard(type) {
2
- return (node) => node.type === type;
3
- }
4
- export const is = {
5
- parent(node) {
6
- return Array.isArray(node.children);
7
- },
8
- literal(node) {
9
- return typeof node.value === 'string';
10
- },
11
- tag(node) {
12
- return node.type === 'element' || node.type === 'custom-element' || node.type === 'component' || node.type === 'fragment';
13
- },
14
- whitespace(node) {
15
- return node.type === 'text' && node.value.trim().length === 0;
16
- },
17
- root: guard('root'),
18
- element: guard('element'),
19
- customElement: guard('custom-element'),
20
- component: guard('component'),
21
- fragment: guard('fragment'),
22
- expression: guard('expression'),
23
- text: guard('text'),
24
- doctype: guard('doctype'),
25
- comment: guard('comment'),
26
- frontmatter: guard('frontmatter'),
27
- };
28
- class Walker {
29
- constructor(callback) {
30
- this.callback = callback;
31
- }
32
- async visit(node, parent, index) {
33
- await this.callback(node, parent, index);
34
- if (is.parent(node)) {
35
- let promises = [];
36
- for (let i = 0; i < node.children.length; i++) {
37
- const child = node.children[i];
38
- promises.push(this.callback(child, node, i));
39
- }
40
- await Promise.all(promises);
41
- }
42
- }
43
- }
44
- export function walk(node, callback) {
45
- const walker = new Walker(callback);
46
- walker.visit(node);
47
- }
48
- function serializeAttributes(node) {
49
- let output = '';
50
- for (const attr of node.attributes) {
51
- output += ' ';
52
- switch (attr.kind) {
53
- case 'empty': {
54
- output += `${attr.name}`;
55
- break;
56
- }
57
- case 'expression': {
58
- output += `${attr.name}={${attr.value}}`;
59
- break;
60
- }
61
- case 'quoted': {
62
- output += `${attr.name}="${attr.value}"`;
63
- break;
64
- }
65
- case 'template-literal': {
66
- output += `${attr.name}=\`${attr.value}\``;
67
- break;
68
- }
69
- case 'shorthand': {
70
- output += `{${attr.name}}`;
71
- break;
72
- }
73
- case 'spread': {
74
- output += `{...${attr.value}}`;
75
- break;
76
- }
77
- }
78
- }
79
- return output;
80
- }
81
- export function serialize(root, opts = { selfClose: true }) {
82
- let output = '';
83
- function visitor(node) {
84
- if (is.root(node)) {
85
- node.children.forEach((child) => visitor(child));
86
- }
87
- else if (is.frontmatter(node)) {
88
- output += `---${node.value}---\n\n`;
89
- }
90
- else if (is.comment(node)) {
91
- output += `<!--${node.value}-->`;
92
- }
93
- else if (is.expression(node)) {
94
- output += `{`;
95
- node.children.forEach((child) => visitor(child));
96
- output += `}`;
97
- }
98
- else if (is.literal(node)) {
99
- output += node.value;
100
- }
101
- else if (is.tag(node)) {
102
- output += `<${node.name}`;
103
- output += serializeAttributes(node);
104
- if (node.children.length == 0 && opts.selfClose) {
105
- output += ` />`;
106
- }
107
- else {
108
- output += '>';
109
- node.children.forEach((child) => visitor(child));
110
- output += `</${node.name}>`;
111
- }
112
- }
113
- }
114
- visitor(root);
115
- return output;
116
- }
@@ -1,35 +0,0 @@
1
- export default class Go {
2
- importObject: {
3
- go: {
4
- 'runtime.wasmExit': (sp: any) => void;
5
- 'runtime.wasmWrite': (sp: any) => void;
6
- 'runtime.resetMemoryDataView': (sp: any) => void;
7
- 'runtime.nanotime1': (sp: any) => void;
8
- 'runtime.walltime': (sp: any) => void;
9
- 'runtime.scheduleTimeoutEvent': (sp: any) => void;
10
- 'runtime.clearTimeoutEvent': (sp: any) => void;
11
- 'runtime.getRandomData': (sp: any) => void;
12
- 'syscall/js.finalizeRef': (sp: any) => void;
13
- 'syscall/js.stringVal': (sp: any) => void;
14
- 'syscall/js.valueGet': (sp: any) => void;
15
- 'syscall/js.valueSet': (sp: any) => void;
16
- 'syscall/js.valueDelete': (sp: any) => void;
17
- 'syscall/js.valueIndex': (sp: any) => void;
18
- 'syscall/js.valueSetIndex': (sp: any) => void;
19
- 'syscall/js.valueCall': (sp: any) => void;
20
- 'syscall/js.valueInvoke': (sp: any) => void;
21
- 'syscall/js.valueNew': (sp: any) => void;
22
- 'syscall/js.valueLength': (sp: any) => void;
23
- 'syscall/js.valuePrepareString': (sp: any) => void;
24
- 'syscall/js.valueLoadString': (sp: any) => void;
25
- 'syscall/js.valueInstanceOf': (sp: any) => void;
26
- 'syscall/js.copyBytesToGo': (sp: any) => void;
27
- 'syscall/js.copyBytesToJS': (sp: any) => void;
28
- debug: (value: any) => void;
29
- };
30
- };
31
- constructor();
32
- run(instance: any): Promise<void>;
33
- private _resume;
34
- private _makeFuncWrapper;
35
- }