-
-
Notifications
You must be signed in to change notification settings - Fork 185
Added override for traceback #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9746a04
Added override for traceback
Perryvw 9140147
Improved sourcemap override
Perryvw 0753524
Removed obsolete argument
Perryvw 765dcc1
put traceback override at start of the file after headers
Perryvw 09ce51f
changed 2 underscore identifiers
Perryvw 752eff3
Merge branch 'source-maps' into feature/sourcemap-traceback
Perryvw debca18
Added test for sourceMapTraceback
Perryvw bc051ec
don't enforce prettier linting
Perryvw 346720a
use debug.getinfo for file names
Perryvw e731c8f
Trying to diagnose test issue
Perryvw 2861bae
No longer check filename in sourcemap test
Perryvw 37ab9bf
Another stab at fixing tests
Perryvw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
| /** @luaIterator */ | ||
| interface GMatchResult extends Iterable<string> { } | ||
| interface GMatchResult extends Array<string> { } | ||
|
|
||
| /** @noSelf */ | ||
| declare namespace string { | ||
| /** @tupleReturn */ | ||
| function gsub(source: string, searchValue: string, replaceValue: string): [string, number]; | ||
| /** @tupleReturn */ | ||
| function gsub(source: string, searchValue: string, replaceValue: (...groups: string[]) => string): [string, number]; | ||
|
|
||
| function gmatch(haystack: string, pattern: string): GMatchResult; | ||
| } | ||
This file contains hidden or 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 hidden or 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,73 @@ | ||
| import * as util from "../util"; | ||
| import { LuaLibImportKind } from "../../src/CompilerOptions"; | ||
|
|
||
| test("sourceMapTraceback saves sourcemap in _G", () => { | ||
| const typeScriptSource = ` | ||
| function abc() { | ||
| return "foo"; | ||
| } | ||
| return JSONStringify(_G.__TS__sourcemap);`; | ||
|
|
||
| const options = {sourceMapTraceback: true, luaLibImport: LuaLibImportKind.Inline}; | ||
|
|
||
| const transpiledLua = util.transpileString(typeScriptSource, options); | ||
|
|
||
| const sourceMapJson = util.transpileAndExecute( | ||
| typeScriptSource, | ||
| options, | ||
| undefined, | ||
| "declare const _G: {__TS__sourcemap: any};" | ||
| ); | ||
|
|
||
| expect(sourceMapJson).toBeDefined(); | ||
|
|
||
| const sourceMap = JSON.parse(sourceMapJson); | ||
|
|
||
| const sourceMapFiles = Object.keys(sourceMap); | ||
|
|
||
| expect(sourceMapFiles.length).toBe(1); | ||
| expect(sourceMap[sourceMapFiles[0]]).toBeDefined(); | ||
|
|
||
| expectCorrectMapping(typeScriptSource, transpiledLua, sourceMap[sourceMapFiles[0]], [ | ||
| ["function abc()", "abc = function("], | ||
| ["return \"foo\"", "return \"foo\""] | ||
| ]); | ||
| }); | ||
|
|
||
| // Helper functions | ||
|
|
||
| function expectCorrectMapping( | ||
| original: string, | ||
| lua: string, | ||
| sourceMap: {[line: string]: number}, | ||
| patterns: Array<[string, string]> | ||
| ): void { | ||
| for (const [tsPattern, luaPattern] of patterns) { | ||
| const originalLine = lineOf(original, "function abc()") + 1; // Add 1 for util-added header | ||
| const luaLine = lineOf(lua, "abc = function("); | ||
| const mappedLuaLine = sourceMap[luaLine.toString()]; | ||
|
|
||
| expect(mappedLuaLine).toBe(originalLine); | ||
| } | ||
| } | ||
|
|
||
| // Find the line of the first occurrence of a pattern. | ||
| function lineOf(text: string, pattern: string): number { | ||
| const pos = text.indexOf(pattern); | ||
| if (pos === -1) { | ||
| return pos; | ||
| } | ||
|
|
||
| const lineLengths = text.split("\n").map(s => s.length); | ||
|
|
||
| let totalPos = 0; | ||
| for (let line = 1; line <= lineLengths.length; line++) { | ||
| // Add length of the line + 1 for the removed \n | ||
| totalPos += lineLengths[line - 1] + 1; | ||
| if (pos < totalPos) { | ||
| return line; | ||
| } | ||
| } | ||
|
|
||
| return -1; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.