Skip to content

Commit 2f185b3

Browse files
d-gubertRafael Tapiapierre-lehnen-rc
authored
feat: New Deno runtime (#665)
Co-authored-by: Rafael Tapia <[email protected]> Co-authored-by: Pierre Lehnen <[email protected]>
1 parent 453fbdb commit 2f185b3

File tree

110 files changed

+9334
-1222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+9334
-1222
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
/docs
55
/server
66
/lib
7+
/deno-runtime
8+
/.deno

.github/workflows/build_and_test.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
branches:
99
- 'alpha'
1010
- 'beta'
11+
- 'feat/deno-runtime'
12+
13+
env:
14+
DENO_DIR: .deno
1115

1216
jobs:
1317
prepare:
@@ -45,13 +49,18 @@ jobs:
4549
id: cache-nodemodules
4650
uses: actions/cache@v2
4751
with:
48-
path: ./node_modules
49-
key: ${{ runner.OS }}-node_modules-4-${{ hashFiles('./package-lock.json', '.github/workflows/build_and_test.yml') }}
52+
path: |
53+
./node_modules
54+
./deno-runtime/${{ env.DENO_DIR }}
55+
key: ${{ runner.OS }}-node_modules-deno-cache-5-${{ hashFiles('./package-lock.json', './deno-runtime/deno.lock', '.github/workflows/build_and_test.yml') }}
5056

5157
- name: npm install
5258
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
5359
run: npm install
5460

61+
- name: Deno Info
62+
run: npx deno-bin info
63+
5564
- name: Prepare workspace
5665
run: |
5766
tar czf /tmp/workspace.tar.gz .
@@ -85,7 +94,7 @@ jobs:
8594

8695
test:
8796
runs-on: ubuntu-latest
88-
needs: prepare
97+
needs: build
8998

9099
steps:
91100
- name: Use Node.js 14.19.3
@@ -103,13 +112,11 @@ jobs:
103112
tar xzf /tmp/workspace.tar.gz .
104113
105114
- name: Test TypeScript Code
106-
run: npm run unit-tests
115+
run: npm run test
107116

108117
build:
109118
runs-on: ubuntu-latest
110-
needs:
111-
- lint
112-
- test
119+
needs: lint
113120

114121
steps:
115122
- name: Use Node.js 14.19.3
@@ -141,7 +148,7 @@ jobs:
141148
publish:
142149
runs-on: ubuntu-latest
143150
if: github.event_name == 'release' || github.ref == 'refs/heads/alpha' || github.ref == 'refs/heads/beta'
144-
needs: build
151+
needs: test
145152

146153
steps:
147154
- name: Use Node.js 14.19.3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ jspm_packages
3737
# Optional npm cache directory
3838
.npm
3939

40+
.deno
41+
4042
# Optional REPL history
4143
.node_repl_history
4244

deno-runtime/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.deno/

deno-runtime/AppObjectRegistry.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export type Maybe<T> = T | null | undefined;
2+
3+
export const AppObjectRegistry = new class {
4+
registry: Record<string, unknown> = {};
5+
6+
public get<T>(key: string): Maybe<T> {
7+
return this.registry[key] as Maybe<T>;
8+
}
9+
10+
public set(key: string, value: unknown): void {
11+
this.registry[key] = value;
12+
}
13+
14+
public has(key: string): boolean {
15+
return key in this.registry;
16+
}
17+
18+
public delete(key: string): void {
19+
delete this.registry[key];
20+
}
21+
22+
public clear(): void {
23+
this.registry = {};
24+
}
25+
}
26+

deno-runtime/acorn-walk.d.ts

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import type acorn from "./acorn.d.ts";
2+
3+
export type FullWalkerCallback<TState> = (
4+
node: acorn.AnyNode,
5+
state: TState,
6+
type: string
7+
) => void
8+
9+
export type FullAncestorWalkerCallback<TState> = (
10+
node: acorn.AnyNode,
11+
state: TState,
12+
ancestors: acorn.AnyNode[],
13+
type: string
14+
) => void
15+
16+
type AggregateType = {
17+
Expression: acorn.Expression,
18+
Statement: acorn.Statement,
19+
Pattern: acorn.Pattern,
20+
ForInit: acorn.VariableDeclaration | acorn.Expression
21+
}
22+
23+
export type SimpleVisitors<TState> = {
24+
[type in acorn.AnyNode["type"]]?: (node: Extract<acorn.AnyNode, { type: type }>, state: TState) => void
25+
} & {
26+
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState) => void
27+
}
28+
29+
export type AncestorVisitors<TState> = {
30+
[type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, ancestors: acorn.Node[]
31+
) => void
32+
} & {
33+
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.Node[]) => void
34+
}
35+
36+
export type WalkerCallback<TState> = (node: acorn.Node, state: TState) => void
37+
38+
export type RecursiveVisitors<TState> = {
39+
[type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, callback: WalkerCallback<TState>) => void
40+
} & {
41+
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback<TState>) => void
42+
}
43+
44+
export type FindPredicate = (type: string, node: acorn.Node) => boolean
45+
46+
export interface Found<TState> {
47+
node: acorn.Node,
48+
state: TState
49+
}
50+
51+
/**
52+
* does a 'simple' walk over a tree
53+
* @param node the AST node to walk
54+
* @param visitors an object with properties whose names correspond to node types in the {@link https://github.com/estree/estree | ESTree spec}. The properties should contain functions that will be called with the node object and, if applicable the state at that point.
55+
* @param base a walker algorithm
56+
* @param state a start state. The default walker will simply visit all statements and expressions and not produce a meaningful state. (An example of a use of state is to track scope at each point in the tree.)
57+
*/
58+
export function simple<TState>(
59+
node: acorn.Node,
60+
visitors: SimpleVisitors<TState>,
61+
base?: RecursiveVisitors<TState>,
62+
state?: TState
63+
): void
64+
65+
/**
66+
* does a 'simple' walk over a tree, building up an array of ancestor nodes (including the current node) and passing the array to the callbacks as a third parameter.
67+
* @param node
68+
* @param visitors
69+
* @param base
70+
* @param state
71+
*/
72+
export function ancestor<TState>(
73+
node: acorn.Node,
74+
visitors: AncestorVisitors<TState>,
75+
base?: RecursiveVisitors<TState>,
76+
state?: TState
77+
): void
78+
79+
/**
80+
* does a 'recursive' walk, where the walker functions are responsible for continuing the walk on the child nodes of their target node.
81+
* @param node
82+
* @param state the start state
83+
* @param functions contain an object that maps node types to walker functions
84+
* @param base provides the fallback walker functions for node types that aren't handled in the {@link functions} object. If not given, the default walkers will be used.
85+
*/
86+
export function recursive<TState>(
87+
node: acorn.Node,
88+
state: TState,
89+
functions: RecursiveVisitors<TState>,
90+
base?: RecursiveVisitors<TState>
91+
): void
92+
93+
/**
94+
* does a 'full' walk over a tree, calling the {@link callback} with the arguments (node, state, type) for each node
95+
* @param node
96+
* @param callback
97+
* @param base
98+
* @param state
99+
*/
100+
export function full<TState>(
101+
node: acorn.Node,
102+
callback: FullWalkerCallback<TState>,
103+
base?: RecursiveVisitors<TState>,
104+
state?: TState
105+
): void
106+
107+
/**
108+
* does a 'full' walk over a tree, building up an array of ancestor nodes (including the current node) and passing the array to the callbacks as a third parameter.
109+
* @param node
110+
* @param callback
111+
* @param base
112+
* @param state
113+
*/
114+
export function fullAncestor<TState>(
115+
node: acorn.AnyNode,
116+
callback: FullAncestorWalkerCallback<TState>,
117+
base?: RecursiveVisitors<TState>,
118+
state?: TState
119+
): void
120+
121+
/**
122+
* builds a new walker object by using the walker functions in {@link functions} and filling in the missing ones by taking defaults from {@link base}.
123+
* @param functions
124+
* @param base
125+
*/
126+
export function make<TState>(
127+
functions: RecursiveVisitors<TState>,
128+
base?: RecursiveVisitors<TState>
129+
): RecursiveVisitors<TState>
130+
131+
/**
132+
* tries to locate a node in a tree at the given start and/or end offsets, which satisfies the predicate test. {@link start} and {@link end} can be either `null` (as wildcard) or a `number`. {@link test} may be a string (indicating a node type) or a function that takes (nodeType, node) arguments and returns a boolean indicating whether this node is interesting. {@link base} and {@link state} are optional, and can be used to specify a custom walker. Nodes are tested from inner to outer, so if two nodes match the boundaries, the inner one will be preferred.
133+
* @param node
134+
* @param start
135+
* @param end
136+
* @param type
137+
* @param base
138+
* @param state
139+
*/
140+
export function findNodeAt<TState>(
141+
node: acorn.AnyNode,
142+
start: number | undefined,
143+
end?: number | undefined,
144+
type?: FindPredicate | string,
145+
base?: RecursiveVisitors<TState>,
146+
state?: TState
147+
): Found<TState> | undefined
148+
149+
/**
150+
* like {@link findNodeAt}, but will match any node that exists 'around' (spanning) the given position.
151+
* @param node
152+
* @param start
153+
* @param type
154+
* @param base
155+
* @param state
156+
*/
157+
export function findNodeAround<TState>(
158+
node: acorn.AnyNode,
159+
start: number | undefined,
160+
type?: FindPredicate | string,
161+
base?: RecursiveVisitors<TState>,
162+
state?: TState
163+
): Found<TState> | undefined
164+
165+
/**
166+
* similar to {@link findNodeAround}, but will match all nodes after the given position (testing outer nodes before inner nodes).
167+
*/
168+
export const findNodeAfter: typeof findNodeAround
169+
170+
export const base: RecursiveVisitors<unknown>

0 commit comments

Comments
 (0)