Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

60 lines
2.2 KiB
Go

package languages
import (
"regexp"
"github.com/zzet/gortex/internal/graph"
"github.com/zzet/gortex/internal/parser"
)
// React Native Fabric / Codegen view-component recognition. A Fabric
// component is declared in a TS spec with
// `codegenNativeComponent<NativeProps>('RCTMyView')`, and its NativeProps
// interface declares event props typed `DirectEventHandler<T>` /
// `BubblingEventHandler<T>`. This spec is the cross-language ground truth
// the native view manager (an ObjC RCTViewManager with
// RCT_EXPORT_VIEW_PROPERTY, or a Java ViewManager with @ReactProp)
// implements. The Fabric synthesizer links the spec to the native manager
// by component name.
var (
// codegenNativeComponent<Props>('Name') — the type arg is optional.
fabricCodegenRe = regexp.MustCompile(`codegenNativeComponent\s*(?:<[^>]*>)?\s*\(\s*['"]([^'"]+)['"]`)
// onChange?: DirectEventHandler<ChangeEvent> / BubblingEventHandler<...>
fabricEventRe = regexp.MustCompile(`(?m)^\s*(\w+)\??\s*:\s*(?:Direct|Bubbling)EventHandler\s*<`)
)
// emitFabricComponentNodes scans a TS/JS Fabric spec for a
// codegenNativeComponent declaration and emits a synthetic component node
// carrying fabric_component plus the event-handler prop names parsed from
// the spec, so the Fabric synthesizer can pair it with the native view
// manager.
func emitFabricComponentNodes(src []byte, filePath, language, fileID string, result *parser.ExtractionResult) {
s := string(src)
comp := fabricCodegenRe.FindStringSubmatch(s)
if comp == nil {
return
}
component := comp[1]
id := filePath + "::fabric:" + component
var events []string
for _, m := range fabricEventRe.FindAllStringSubmatch(s, -1) {
events = append(events, m[1])
}
line := lineAt(src, fabricCodegenRe.FindStringIndex(s)[0])
node := &graph.Node{
ID: id, Kind: graph.KindType, Name: component,
FilePath: filePath, StartLine: line, EndLine: line,
Language: language,
Meta: map[string]any{"fabric_component": component, "type_flavor": "component", "ui_component": "react"},
}
if len(events) > 0 {
node.Meta["fabric_events"] = events
}
result.Nodes = append(result.Nodes, node)
result.Edges = append(result.Edges, &graph.Edge{
From: fileID, To: id, Kind: graph.EdgeDefines, FilePath: filePath, Line: line,
})
}