-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Note that names are placeholders
- Loading branch information
Showing
18 changed files
with
289 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
src/LuauRenderer/nodes/expressions/indexable/renderIdentifier.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
import luau from "LuauAST"; | ||
import { isNone } from "LuauAST/bundle"; | ||
import { assert } from "LuauAST/util/assert"; | ||
import { RenderState } from "LuauRenderer"; | ||
import { render, RenderState } from "LuauRenderer"; | ||
|
||
export function renderIdentifier(state: RenderState, node: luau.Identifier) { | ||
assert(luau.isValidIdentifier(node.name), `Invalid Luau Identifier: "${node.name}"`); | ||
return node.name; | ||
} | ||
|
||
export function renderIdentifierWithType(state: RenderState, node: luau.Identifier) { | ||
if (node.annotation && !isNone(node)) { | ||
return `${node.name}: ${render(state, node.annotation)}`; | ||
} | ||
return node.name; | ||
} |
12 changes: 11 additions & 1 deletion
12
src/LuauRenderer/nodes/expressions/indexable/renderTemporaryIdentifier.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
import luau from "LuauAST"; | ||
import { isNode } from "LuauAST/bundle"; | ||
import { assert } from "LuauAST/util/assert"; | ||
import { RenderState } from "LuauRenderer"; | ||
import { render, RenderState } from "LuauRenderer"; | ||
|
||
export function renderTemporaryIdentifier(state: RenderState, node: luau.TemporaryIdentifier) { | ||
const name = state.getTempName(node); | ||
assert(luau.isValidIdentifier(name), `Invalid Temporary Identifier: "${name}"`); | ||
return name; | ||
} | ||
|
||
export function renderTemporaryIdentifierWithType(state: RenderState, node: luau.TemporaryIdentifier) { | ||
const name = state.getTempName(node); | ||
assert(luau.isValidIdentifier(name), `Invalid Temporary Identifier: "${name}"`); | ||
if (node.annotation && !isNode(node.annotation)) { | ||
return `${name}: ${render(state, node.annotation)}`; | ||
} | ||
return name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import luau from "LuauAST"; | ||
import { render, RenderState } from "LuauRenderer"; | ||
|
||
export function renderTypeDeclaration(state: RenderState, node: luau.TypeStatement) { | ||
return state.line(`type ${render(state, node.identifier)} = ${render(state, node.expression)}`); | ||
} |
6 changes: 3 additions & 3 deletions
6
src/LuauRenderer/nodes/statements/renderVariableDeclaration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import luau from "LuauAST"; | ||
import { render, RenderState } from "LuauRenderer"; | ||
|
||
export function renderMixedTableType(state: RenderState, node: luau.TypeMixedTable) { | ||
const inner: Array<string> = []; | ||
for (const field of luau.list.toArray(node.fields)) { | ||
inner.push(render(state, field)); | ||
} | ||
return `{ ${inner.join(", ")} }`; | ||
} | ||
|
||
export function renderMixedTableFieldType(state: RenderState, node: luau.TypeMixedTableField) { | ||
if (!luau.isValidIdentifier(node.index.name)) { | ||
return `["${node.index.name}"]: ${render(state, node.value)}`; | ||
} | ||
return `${render(state, node.index)}: ${render(state, node.value)}`; | ||
} | ||
|
||
export function renderMixedTableIndexedFieldType(state: RenderState, node: luau.TypeMixedTableIndexedField) { | ||
return `[${render(state, node.index)}]: ${render(state, node.value)}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import luau from "LuauAST"; | ||
import { render, RenderState } from "LuauRenderer"; | ||
|
||
export function renderTypeCast(state: RenderState, node: luau.TypeCast) { | ||
return `(${render(state, node.expression)} :: ${render(state, node.type)})`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import luau from "LuauAST"; | ||
import { render, RenderState } from "LuauRenderer"; | ||
|
||
export function renderTypeFunction(state: RenderState, node: luau.TypeFunction) { | ||
let params: string; | ||
|
||
if (node.parameters !== undefined) { | ||
const rendered = luau.list.mapToArray(node.parameters, expr => render(state, expr)); | ||
if (node.dotDotDot) { | ||
rendered.push(`...${render(state, node.dotDotDot)}`); | ||
} | ||
params = rendered.join(", "); | ||
} else { | ||
if (node.dotDotDot) { | ||
params = `...${render(state, node.dotDotDot)}`; | ||
} else { | ||
params = "...any"; | ||
} | ||
} | ||
|
||
return `(${params}) -> ${node.returnType ? render(state, node.returnType) : "()"}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import assert from "assert"; | ||
import luau from "LuauAST"; | ||
import { RenderState } from "LuauRenderer"; | ||
|
||
export function renderTypeIdentifier(state: RenderState, node: luau.TypeIdentifier) { | ||
assert(luau.isValidIdentifier(node.name), `Invalid Luau Identifier: "${node.name}"`); | ||
if (node.module) return `${node.module}.${node.name}`; | ||
return node.name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import luau from "LuauAST"; | ||
import { render, RenderState } from "LuauRenderer"; | ||
|
||
export function renderTypeOf(state: RenderState, node: luau.TypeTypeOf) { | ||
return `typeof(${render(state, node.expression)})`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import luau from "LuauAST"; | ||
import { assert } from "LuauAST/util/assert"; | ||
import { render, RenderState } from "LuauRenderer"; | ||
|
||
export function renderTypeParameter(state: RenderState, node: luau.TypeParameter) { | ||
if (node.name) { | ||
assert(luau.isValidIdentifier(node.name), `Invalid Luau Identifier: "${node.name}"`); | ||
return `${node.name}: ${render(state, node.value)}`; | ||
} | ||
|
||
return render(state, node.value); | ||
} |
Oops, something went wrong.