From 911b0e00170637b843b510c0617d52b51e2016bc Mon Sep 17 00:00:00 2001 From: Yuxiao Mao Date: Fri, 31 May 2024 12:45:17 +0200 Subject: [PATCH] Use hscript to manage ?. include revert of eb4605a8 --- .github/workflows/main.yml | 2 +- README.md | 4 ++-- hld/Eval.hx | 14 ++++++++++++-- src/HLAdapter.hx | 2 -- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bf39a41..ee1f22f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: - name: Install haxelib dependencies run: | haxelib git format https://github.com/HaxeFoundation/format.git - haxelib install hscript + haxelib git hscript https://github.com/HaxeFoundation/hscript.git haxelib install vshaxe haxelib install vscode haxelib install vscode-debugadapter diff --git a/README.md b/README.md index a8be8fa..0061b70 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ Additionally, you need to install these dependencies: haxelib install vshaxe haxelib install vscode haxelib install vscode-debugadapter -haxelib install hscript -haxelib install format +haxelib git hscript https://github.com/HaxeFoundation/hscript.git +haxelib git format https://github.com/HaxeFoundation/format.git ``` You will need [NodeJS](https://nodejs.org/en/download), if you would like to compile vscode extension or use commandline nodejs version. diff --git a/hld/Eval.hx b/hld/Eval.hx index b2b83dc..8143d78 100644 --- a/hld/Eval.hx +++ b/hld/Eval.hx @@ -237,8 +237,18 @@ class Eval { } case EBlock(el): var v : Value = { v : VNull, t : HDyn }; - for( e in el ) - v = evalExpr(e); + switch(el) { + case [EVar(id,_,e), ETernary(EBinop("==",EIdent(id2),EIdent("null")), EIdent("null"), EField(EIdent(id3),f))] if ( id == id2 && id == id3 ): + // Special case for e?.field + var ve : Value = evalExpr(e); + if( compare(ve, v) != 0 ) { + v = readField(ve, f); + if( v == null ) throw valueStr(ve)+" has no field "+f; + } + default: + for( e in el ) + v = evalExpr(e); + } return v; case EField(e, f): var e = e; diff --git a/src/HLAdapter.hx b/src/HLAdapter.hx index 0fd4de8..c8c6742 100644 --- a/src/HLAdapter.hx +++ b/src/HLAdapter.hx @@ -948,8 +948,6 @@ class HLAdapter extends DebugSession { // ?ident => hover on optional param (most likely) if( ~/^\?[A-Za-z0-9_]+$/.match(args.expression) ) args.expression = args.expression.substr(1); - // ?. => likely null safe field access, replace to . - args.expression = StringTools.replace(args.expression, "?.", "."); if( KEYWORDS.exists(args.expression) ) { // Do nothing } else {