From 9f630d5cf296172f9671d005b7057bd898c92456 Mon Sep 17 00:00:00 2001 From: AlexHaxe Date: Wed, 4 Nov 2020 23:42:19 +0100 Subject: [PATCH] fixed array type parameter (#201) * fixed array type parameter --- CHANGELOG.md | 4 ++++ haxelib.json | 4 ++-- package-lock.json | 2 +- package.json | 2 +- src/tokentree/TokenStream.hx | 9 ++++++++- src/tokentree/walk/WalkStatement.hx | 2 +- test/tokentree/TestTokenTreeBuilder.hx | 4 ++-- test/tokentree/TokenTreeBuilderParsingTest.hx | 4 ++++ test/tokentree/utils/TokenTreeCheckUtilsTest.hx | 7 ++++++- 9 files changed, 29 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38d028b..d6b7ffc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## dev branch / next version (1.x.x) +## version 1.0.31 (2020-11-04) + +- Fixed type parameter with array ([#201](https://github.com/HaxeCheckstyle/tokentree/issues/201)) + ## version 1.0.30 (2020-11-02) - Fixed arrow functions ([#200](https://github.com/HaxeCheckstyle/tokentree/issues/200)) diff --git a/haxelib.json b/haxelib.json index d627d71..89a4780 100644 --- a/haxelib.json +++ b/haxelib.json @@ -7,8 +7,8 @@ "contributors": [ "AlexHaxe" ], - "releasenote": "fixed type parameter and dollar handling - see CHANGELOG for details", - "version": "1.0.30", + "releasenote": "fixed type parameter handling - see CHANGELOG for details", + "version": "1.0.31", "url": "https://github.com/HaxeCheckstyle/tokentree", "dependencies": {} } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ac51fb8..c9c5b7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "tokentree", - "version": "1.0.30", + "version": "1.0.31", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 6acdf9e..e32c941 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tokentree", - "version": "1.0.30", + "version": "1.0.31", "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 1b6c13b..b56ecab 100644 --- a/src/tokentree/TokenStream.hx +++ b/src/tokentree/TokenStream.hx @@ -143,6 +143,7 @@ class TokenStream { } var depth:Int = 1; var brDepth:Int = 0; + var bkDepth:Int = 0; var pDepth:Int = 0; while (true) { token = tokens[index++]; @@ -165,8 +166,14 @@ class TokenStream { return false; } brDepth--; + case BkOpen: + bkDepth++; + case BkClose: + if (bkDepth <= 0) { + return false; + } + bkDepth--; case Const(_): - // case Kwd(_): case Dollar(_): case Binop(OpLt): depth++; diff --git a/src/tokentree/walk/WalkStatement.hx b/src/tokentree/walk/WalkStatement.hx index 64a276d..0cb0521 100644 --- a/src/tokentree/walk/WalkStatement.hx +++ b/src/tokentree/walk/WalkStatement.hx @@ -175,7 +175,7 @@ class WalkStatement { while (true) { switch (ltParent.tok) { case Root: break; - case Dot | DblDot | Comma | Arrow | POpen | Const(_) | Dollar(_) | Binop(OpGt): ltParent = ltParent.parent; + case Dot | DblDot | Comma | Arrow | POpen | Const(_) | Dollar(_) | BkOpen | BrOpen | Binop(OpGt): ltParent = ltParent.parent; case Binop(OpLt): return; default: break; } diff --git a/test/tokentree/TestTokenTreeBuilder.hx b/test/tokentree/TestTokenTreeBuilder.hx index 803d376..0e1639c 100644 --- a/test/tokentree/TestTokenTreeBuilder.hx +++ b/test/tokentree/TestTokenTreeBuilder.hx @@ -1,10 +1,10 @@ package tokentree; import byte.ByteData; -import haxeparser.HaxeLexer; import haxeparser.Data.Token; -import tokentree.walk.WalkFile; +import haxeparser.HaxeLexer; import tokentree.TokenTreeBuilder.TokenTreeEntryPoint; +import tokentree.walk.WalkFile; class TestTokenTreeBuilder extends TokenTreeBuilder { public static function parseCode(code:String):TestTokenTreeBuilder { diff --git a/test/tokentree/TokenTreeBuilderParsingTest.hx b/test/tokentree/TokenTreeBuilderParsingTest.hx index af4fa2c..2ec28cd 100644 --- a/test/tokentree/TokenTreeBuilderParsingTest.hx +++ b/test/tokentree/TokenTreeBuilderParsingTest.hx @@ -124,6 +124,7 @@ class TokenTreeBuilderParsingTest implements ITest { assertCodeParses(CALLBACK_TYPE_PARAM); assertCodeParses(MAP_INIT_WITH_COMMENT); assertCodeParses(DOLLAR_CHAIN); + assertCodeParses(TYPE_PARAM_WITH_ARRAY); } public function assertCodeParses(code:String, ?pos:PosInfos) { @@ -1668,4 +1669,7 @@ import #if haxe4 js.lib.Promise #else js.Promise #end as JsPromise; }); } }"; + + var TYPE_PARAM_WITH_ARRAY = " + private typedef Init = haxe.macro.MacroType<[cdb.Module.build('data.cdb')]>;"; } \ No newline at end of file diff --git a/test/tokentree/utils/TokenTreeCheckUtilsTest.hx b/test/tokentree/utils/TokenTreeCheckUtilsTest.hx index 8ae3c9e..3546470 100644 --- a/test/tokentree/utils/TokenTreeCheckUtilsTest.hx +++ b/test/tokentree/utils/TokenTreeCheckUtilsTest.hx @@ -457,7 +457,7 @@ class TokenTreeCheckUtilsTest implements ITest { default: GoDeeper; } }); - Assert.equals(1, allBr.length); + Assert.equals(5, allBr.length); var index:Int = 0; // abstract SymbolStack(Array<{level:SymbolLevel, symbol:DocumentSymbol}>) {} Assert.isTrue(TokenTreeCheckUtils.isTypeParameter(allBr[index++])); @@ -925,6 +925,11 @@ abstract TokenTreeCheckUtilsTests(String) to String { var MIXED_TYPE_PARAMETER = " abstract SymbolStack(Array<{level:SymbolLevel, symbol:DocumentSymbol}>) {} + private typedef Init = haxe.macro.MacroType<[cdb.Module.build('data.cdb')]>; + abstract SymbolStack(haxe.macro.MacroType<[cdb.Module.build('data.cdb')]>) {} + function main(){ + var obj:Null<{field:Null}> = null; + } "; var MIXED_OP_SUB = "