diff --git a/.haxerc b/.haxerc index 98d2f73..e9a39c9 100644 --- a/.haxerc +++ b/.haxerc @@ -1,4 +1,4 @@ { - "version": "5645ecc", + "version": "660947b", "resolveLibs": "scoped" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b6852d..fca28df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## dev branch / next version (1.x.x) +## version 1.2.6 (2023-02-06) + +- Fixed pos info of Root nodes, fixes [#215](https://github.com/HaxeCheckstyle/tokentree/issues/215) + ## version 1.2.5 (2022-12-03) - Fixed ternary detection ([#214](https://github.com/HaxeCheckstyle/tokentree/issues/214)) diff --git a/haxelib.json b/haxelib.json index 0e24c0b..27be521 100644 --- a/haxelib.json +++ b/haxelib.json @@ -7,8 +7,8 @@ "contributors": [ "AlexHaxe" ], - "releasenote": "fixed terenary detection - see CHANGELOG for details", - "version": "1.2.5", + "releasenote": "fixed pos info of root nodes - see CHANGELOG for details", + "version": "1.2.6", "url": "https://github.com/HaxeCheckstyle/tokentree", "dependencies": {} } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d184066..08a3faf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tokentree", - "version": "1.2.5", + "version": "1.2.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "tokentree", - "version": "1.2.5", + "version": "1.2.6", "license": "MIT", "devDependencies": { "lix": "^15.12.0" diff --git a/package.json b/package.json index d28ce4a..1242b7f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tokentree", - "version": "1.2.5", + "version": "1.2.6", "description": "TokenTree library used by haxe-checkstyle, haxe-formatter and haxe-languageserver", "repository": { "type": "git", diff --git a/src/tokentree/TokenStream.hx b/src/tokentree/TokenStream.hx index daea242..4918573 100644 --- a/src/tokentree/TokenStream.hx +++ b/src/tokentree/TokenStream.hx @@ -389,8 +389,11 @@ class TokenStream { return sharpIfStack[sharpIfStack.length - 1]; } - function createDummyToken(tokDef:TokenTreeDef):TokenTree { + public function createDummyToken(tokDef:TokenTreeDef):TokenTree { var pos:Position; + if (tokens.length <= 0) { + return new TokenTree(tokDef, "", {file: "", min: 0, max: 0}, -1, true); + } if ((current < 0) || (current >= tokens.length)) { var prevPos:Position = tokens[tokens.length - 1].pos; pos = { diff --git a/src/tokentree/TokenTree.hx b/src/tokentree/TokenTree.hx index 8fb3121..17504ef 100644 --- a/src/tokentree/TokenTree.hx +++ b/src/tokentree/TokenTree.hx @@ -21,7 +21,7 @@ class TokenTree { @:allow(tokentree.utils.TokenTreeCheckUtils) var tokenTypeCache:TokenTypeCache; - public function new(tok:TokenTreeDef, space:String, pos:Null, index:Int, inserted:Bool = false) { + public function new(tok:TokenTreeDef, space:String, pos:Position, index:Int, inserted:Bool = false) { this.tok = tok; this.pos = pos; this.index = index; diff --git a/src/tokentree/TokenTreeBuilder.hx b/src/tokentree/TokenTreeBuilder.hx index 3677ef5..d4712c4 100644 --- a/src/tokentree/TokenTreeBuilder.hx +++ b/src/tokentree/TokenTreeBuilder.hx @@ -1,11 +1,11 @@ package tokentree; -import haxeparser.Data; -import tokentree.walk.WalkTypeNameDef; import byte.ByteData; +import haxeparser.Data; import tokentree.walk.WalkClass; import tokentree.walk.WalkFile; import tokentree.walk.WalkStatement; +import tokentree.walk.WalkTypeNameDef; class TokenTreeBuilder { public static function buildTokenTree(tokens:Array, bytes:ByteData, entryPoint:Null = null):TokenTree { @@ -16,7 +16,7 @@ class TokenTreeBuilder { } static function buildTokenTreeFromStream(stream:TokenStream, entryPoint:TokenTreeEntryPoint):TokenTree { - var root:TokenTree = new TokenTree(Root, "", null, -1); + var root:TokenTree = stream.createDummyToken(Root); switch (entryPoint) { case TypeLevel: WalkFile.walkFile(stream, root);