Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/files/BrsFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2205,6 +2205,19 @@ describe('BrsFile', () => {
});

describe('transpile', () => {
it('namespaced functions default param values in d.bs files are transpiled correctly', () => {
testGetTypedef(`
namespace alpha
function beta()
end function
function charlie(fn = alpha.beta, fn2 = beta)
end function
end namespace
function delta(fn = alpha.beta)
end function
`);
});

describe('null tokens', () => {
it('succeeds when token locations are omitted', () => {
doTest(`
Expand Down
7 changes: 7 additions & 0 deletions src/parser/AstNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ export abstract class AstNode {

public abstract transpile(state: BrsTranspileState): TranspileResult;

/**
* Get the typedef for this node. (defaults to transpiling the node, should be overridden by subclasses if there's a more specific typedef requirement)
*/
public getTypedef(state: BrsTranspileState) {
return this.transpile(state);
}

/**
* When being considered by the walk visitor, this describes what type of element the current class is.
*/
Expand Down
19 changes: 16 additions & 3 deletions src/parser/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,12 @@ export class FunctionParameterExpression extends Expression {
const results = [this.name.text] as TranspileResult;

if (this.defaultValue) {
results.push(' = ', ...this.defaultValue.transpile(state));
results.push(' = ', ...(this.defaultValue.getTypedef(state) ?? this.defaultValue.transpile(state)));
}

if (this.asToken) {
results.push(' as ');

// TODO: Is this conditional needed? Will typeToken always exist
// so long as `asToken` exists?
if (this.typeToken) {
results.push(this.typeToken.text);
}
Expand Down Expand Up @@ -581,6 +579,15 @@ export class DottedGetExpression extends Expression {
}
}

getTypedef(state: BrsTranspileState) {
//always transpile the dots for typedefs
return [
...this.obj.transpile(state),
state.transpileToken(this.dot),
state.transpileToken(this.name)
];
}

walk(visitor: WalkVisitor, options: WalkOptions) {
if (options.walkMode & InternalWalkMode.walkExpressions) {
walk(this, 'obj', visitor, options);
Expand Down Expand Up @@ -1132,6 +1139,12 @@ export class VariableExpression extends Expression {
return result;
}

getTypedef(state: BrsTranspileState) {
return [
state.transpileToken(this.name)
];
}

walk(visitor: WalkVisitor, options: WalkOptions) {
//nothing to walk
}
Expand Down
Loading