Skip to content

Commit

Permalink
concatanates source literal file paths so that the transpiled output …
Browse files Browse the repository at this point in the history
…does not cause issues with roku's static analysis tool (#415)

* concatanates source literal file paths so that the transpiled output does not cause issues with roku's static analysis tool

* minor docs fix

Co-authored-by: Bronley Plumb <bronley@gmail.com>
  • Loading branch information
georgejecook and TwitchBronBron committed May 14, 2021
1 parent 894ace8 commit 3bf2286
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 7 additions & 2 deletions docs/source-literals.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ print SOURCE_FILE_PATH
transpiles to:

```BrightScript
print "file:///c:/projects/roku/brighterscript/scripts/rootDir/source/main.bs"
print "file" + ":///c:/projects/roku/brighterscript/scripts/rootDir/source/main.bs"
```

_note: the literal is concatenated to keep the roku static analysis tool happy_

## SOURCE_LINE_NUM
The 1-based line number of the source file.

Expand Down Expand Up @@ -153,10 +155,13 @@ transpiles to:

```BrightScript
function main()
print "file:///c:/projects/roku/brighterscript/scripts/rootDir/source/main.bs:2"
print "file" + ":///c:/projects/roku/brighterscript/scripts/rootDir/source/main.bs:2"
end function
```

_note: the literal is concatenated to keep the roku static analysis tool happy_


## PKG_PATH
The pkg path of the file.

Expand Down
6 changes: 4 additions & 2 deletions src/parser/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,8 @@ export class SourceLiteralExpression extends Expression {
let text: string;
switch (this.token.kind) {
case TokenKind.SourceFilePathLiteral:
text = `"${fileUrl(state.srcPath)}"`;
const pathUrl = fileUrl(state.srcPath);
text = `"${pathUrl.substring(0, 4)}" + "${pathUrl.substring(4)}"`;
break;
case TokenKind.SourceLineNumLiteral:
text = `${this.token.range.start.line + 1}`;
Expand All @@ -856,7 +857,8 @@ export class SourceLiteralExpression extends Expression {
text = `"${this.getFunctionName(state, ParseMode.BrighterScript)}"`;
break;
case TokenKind.SourceLocationLiteral:
text = `"${fileUrl(state.srcPath)}:${this.token.range.start.line + 1}"`;
const locationUrl = fileUrl(state.srcPath);
text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.token.range.start.line + 1}"`;
break;
case TokenKind.PkgPathLiteral:
let pkgPath1 = `pkg:/${state.file.pkgPath}`
Expand Down
8 changes: 4 additions & 4 deletions src/parser/tests/expression/SourceLiteralExpression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('SourceLiteralExpression', () => {
end sub
`, `
sub main()
print "${fileUrl(`${rootDir}/source/main.bs`)}"
print "${fileUrl(`${rootDir}/source/main.bs`).substring(0, 4)}" + "${fileUrl(`${rootDir}/source/main.bs`).substring(4)}"
end sub
`, undefined, 'source/main.bs');
});
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('SourceLiteralExpression', () => {
end sub
`, `
sub main()
print "${fileUrl(`${rootDir}/source/main.bs`)}:3"
print "${fileUrl(`${rootDir}/source/main.bs`).substring(0, 4)}" + "${fileUrl(`${rootDir}/source/main.bs`).substring(4)}:3"
end sub
`, undefined, 'source/main.bs');
});
Expand Down Expand Up @@ -188,7 +188,7 @@ describe('SourceLiteralExpression', () => {
end sub
`, `
sub main()
print "${fileUrl(s`${sourceRoot}/source/main.bs`)}"
print "${fileUrl(s`${sourceRoot}/source/main.bs`).substring(0, 4)}" + "${fileUrl(s`${sourceRoot}/source/main.bs`).substring(4)}"
end sub
`, undefined, 'source/main.bs');
});
Expand All @@ -205,7 +205,7 @@ describe('SourceLiteralExpression', () => {
end sub
`, `
sub main()
print "${fileUrl(`${sourceRoot}/source/main.bs`)}:3"
print "${fileUrl(s`${sourceRoot}/source/main.bs`).substring(0, 4)}" + "${fileUrl(s`${sourceRoot}/source/main.bs`).substring(4)}:3"
end sub
`, undefined, 'source/main.bs');
});
Expand Down

0 comments on commit 3bf2286

Please sign in to comment.