luaut-parser 1.0.0 → 1.1.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/README.md +17 -2
- package/dist/index.cjs +381 -25
- package/dist/index.d.cts +73 -7
- package/dist/index.d.ts +73 -7
- package/dist/index.js +380 -25
- package/dist/luau.d.luaut +245 -244
- package/dist/roblox.d.luaut +503 -503
- package/package.json +43 -40
package/README.md
CHANGED
|
@@ -28,7 +28,13 @@ for (const d of [...scopes.diagnostics, ...types.diagnostics]) console.log(d.mes
|
|
|
28
28
|
|---|---|---|
|
|
29
29
|
| `parse(source)` | `Program` — every node carries `line`/`column` spans | everything |
|
|
30
30
|
| `analyzeScopes(program, opts)` | `bindingOf`, `bindings`, `references`, `diagnostics` | go-to-definition, find-references, rename |
|
|
31
|
-
| `analyzeTypes(program, scopes, opts)` | `typeOf`, `narrowedTypeOf`, `bindingType`, `aliases`, `diagnostics` | hover, assignability errors |
|
|
31
|
+
| `analyzeTypes(program, scopes, opts)` | `typeOf`, `narrowedTypeOf`, `bindingType`, `typeOfTypeNode`, `aliases`, `diagnostics` | hover, assignability errors |
|
|
32
|
+
|
|
33
|
+
Every name in the AST has a node with its own span — including the ones that
|
|
34
|
+
used to be bare strings: `DeclareStatement.id`, `TableTypeProperty.key`,
|
|
35
|
+
`FunctionTypeParameter.id`, `GenericTypeParameter.id`, `InferTypeNode.id`,
|
|
36
|
+
`MappedTypeNode.parameterId`. `typeOfTypeNode` gives what each type
|
|
37
|
+
annotation resolves to, so a tool never has to re-derive a type from text.
|
|
32
38
|
|
|
33
39
|
`parseWithRecovery(source)` returns `{ program, errors }` instead of throwing —
|
|
34
40
|
use it for editors, where the text is usually mid-edit.
|
|
@@ -92,6 +98,11 @@ written in luaut on top of those, not built in.
|
|
|
92
98
|
|
|
93
99
|
`<const T>` infers an argument at its narrowest, as in TypeScript 5.
|
|
94
100
|
|
|
101
|
+
`typeof x` in a type is TypeScript's type query — the type of a value
|
|
102
|
+
(`typeof config`, `typeof config.volume`, `ReturnType<typeof f>`). Luau's
|
|
103
|
+
`typeof(expr)` spelling works too. It is compile-time only, unrelated to the
|
|
104
|
+
`typeof(v)` function that returns a string at runtime.
|
|
105
|
+
|
|
95
106
|
## Options
|
|
96
107
|
|
|
97
108
|
```ts
|
|
@@ -104,12 +115,16 @@ analyzeTypes(program, scopes, {
|
|
|
104
115
|
globalTypes: { … }, // types for specific globals; wins over `libs`
|
|
105
116
|
libTypes: { … }, // extra named types for annotations
|
|
106
117
|
diagnostics: true, // emit assignability errors (default)
|
|
118
|
+
resolveModule: specifier => exportsOfThatFile,
|
|
119
|
+
// what an `import` sees; without it imports are `any`
|
|
107
120
|
})
|
|
108
121
|
```
|
|
109
122
|
|
|
110
123
|
## Known limitations
|
|
111
124
|
|
|
112
|
-
-
|
|
125
|
+
- `export * as ns from` and namespace imports (`import * as ns`) are not
|
|
126
|
+
supported. Export lists (`export { a, b as c }`), re-exports
|
|
127
|
+
(`export { a } from`) and `export * from` are.
|
|
113
128
|
- `setmetatable` and metatables are not modelled.
|
|
114
129
|
- Accessing a property a type does not have yields `unknown` rather than an
|
|
115
130
|
error; assigning to a `readonly` property is not reported; generic
|