Skip to content

Commit

Permalink
support blocks generated from static class methods (#10188)
Browse files Browse the repository at this point in the history
  • Loading branch information
riknoll authored Sep 16, 2024
1 parent b269289 commit fe3898c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions localtypings/pxtarget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ declare namespace ts.pxtc {
pyName?: string;
pyQName?: string;
snippetAddsDefinitions?: boolean;
isStatic?: boolean;
}

interface ApisInfo {
Expand Down
4 changes: 3 additions & 1 deletion pxtcompiler/emitter/annotate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ namespace ts.pxtc {
case SK.SetAccessor:
case SK.MethodDeclaration:
case SK.MethodSignature:
isMethod = true
if (!isStatic(decl)) {
isMethod = true
}
break;
default:
break;
Expand Down
1 change: 1 addition & 0 deletions pxtcompiler/emitter/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ namespace ts.pxtc {
pkg,
pkgs,
extendsTypes,
isStatic: decl.modifiers?.some(m => m.kind === SyntaxKind.StaticKeyword),
retType:
stmt.kind == SyntaxKind.Constructor ? "void" :
kind == SymbolKind.Module ? "" :
Expand Down
2 changes: 1 addition & 1 deletion pxtlib/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace pxt.blocks {
handlerArgs: []
};

const instance = (fn.kind == ts.pxtc.SymbolKind.Method || fn.kind == ts.pxtc.SymbolKind.Property) && !fn.attributes.defaultInstance;
const instance = (fn.kind == ts.pxtc.SymbolKind.Method || fn.kind == ts.pxtc.SymbolKind.Property) && !fn.attributes.defaultInstance && !fn.isStatic;
const hasBlockDef = !!fn.attributes._def;
const defParameters = hasBlockDef ? fn.attributes._def.parameters.slice(0) : undefined;
const optionalStart = hasBlockDef ? defParameters.length : (fn.parameters ? fn.parameters.length : 0);
Expand Down

0 comments on commit fe3898c

Please sign in to comment.