source since v0.1.0
Assoc a node child within an AST. After the new child
is inserted into the
children, all Nodes in node
will be re-identified.
Params
context
: Context
- The current parser Context
index
: Integer
- The child index to assoc
child
: Node
- The new child to place at the given `index`
node
: Node
- The target Node whose child is being assoc'd
Returns
Node
- A new copy of the Node with the child assoc'd
Example
source since v0.1.0
Sets up the Context object for use by the parser and generator
Params None
Returns
Context
-
Example
const contxt = setupContext()
source since v0.1.0
Generates a rules file from the given ast
or tokenList
and outputs the
rules to the given outpitFilePath
. If no outputFilePath
is given, a
string is returned.
Params
context
: Context
-
options
: {
-
ast: AST,
outputFilePath: String,
tokenList: List<Token>
}}
Returns
String
-
Example
import { generate, parse, setupContext } from 'firetree'
const context = setupContext()
// parse rules into an AST
const ast = await parse(context, {
string: 'function () { return true }'
})
// generate rules and output to file
const ast = await generate(context, {
ast,
outputFilePath: 'path/to/firestore.rules'
})
source since v0.1.0
parses the rules file at the given filePath
or parse the given string
.
Params
context
: Context
-
options
: {
-
filePath: String,
string: String
}}
Returns
AST
-
Example
import { parse, setupContext } from 'firetree'
const context = setupContext()
// parse file into an AST
const ast = await parse(context, {
filePath: './path/to/firestore.rules'
})
// parse string into an AST
const ast = await parse(context, {
string: someRulesString
})
source since v0.1.0
This method generates a specific object instance for use in a WeakMap cache.
The object instance is unique based upon the parameters that are passed to
the this method.
The main use of this method is for generating cache keys for memoization and
automatically clearing the cache when a value no longer exists in memory.
When a non immutable object is passed as an argument it will be stored into a
WeakMap as part of a chain. If that object is ever removed from memory all
cache chains connected to the object will automatically be removed from the cache.
Params
args
: ...*
- The arguments to generate a cache key for
Returns
Object
- The cache key
Example
source since v0.1.0
Defines length
for the given func
Note: This mutates func
Params
func
: Function
- The function to define the length of.
length
: Number
- The length of the function parameters.
Returns
Function
- The func
function.
Example
const result = functionDefineLength(function (abc) {}, 2)
result.length
//=> 2