typescript-merge 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/lib/typescript/merge/version.rb +11 -0
- data/lib/typescript/merge.rb +145 -0
- data/lib/typescript-merge.rb +3 -0
- data.tar.gz.sig +0 -0
- metadata +110 -0
- metadata.gz.sig +2 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2b6fe33eb2fd3b77c7055bc48c46ae35dc55128a1ac641f7561f226eafbfdd42
|
|
4
|
+
data.tar.gz: 8f17de0ab38fbd970f75149281a58f237c0cff91a8fd8da21f981ac5871e885d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2554eaa84e861bc8d20a7ce6da6fcea064e73b88ebaec6685c3ed6534f3395b69322a76fb85987aba3f572346369fab18d672312ab298cbd221dccfb8f40a17d
|
|
7
|
+
data.tar.gz: 68f5d3f18052f9cf1c3f38f13f40c1ab754bb6d003ad82d81415f59fbb4130c6a92c98913bfd0156ceb817c6a740bb8ba6d679d66f3874121511b3f64058f0fc
|
checksums.yaml.gz.sig
ADDED
|
Binary file
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "tree_haver"
|
|
4
|
+
require "ast/merge"
|
|
5
|
+
|
|
6
|
+
module TypeScript
|
|
7
|
+
module Merge
|
|
8
|
+
extend self
|
|
9
|
+
|
|
10
|
+
PACKAGE_NAME = "typescript-merge"
|
|
11
|
+
TREE_SITTER_BACKEND = TreeHaver::KREUZBERG_LANGUAGE_PACK_BACKEND
|
|
12
|
+
DESTINATION_WINS_ARRAY_POLICY = { surface: "array", name: "destination_wins_array" }.freeze
|
|
13
|
+
|
|
14
|
+
def type_script_feature_profile
|
|
15
|
+
{ family: "typescript", supported_dialects: ["typescript"], supported_policies: [DESTINATION_WINS_ARRAY_POLICY] }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def available_type_script_backends
|
|
19
|
+
[TREE_SITTER_BACKEND]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def type_script_backend_feature_profile(backend: nil)
|
|
23
|
+
requested = backend.to_s.empty? ? TREE_SITTER_BACKEND.id : backend.to_s
|
|
24
|
+
return unsupported_feature_result("Unsupported TypeScript backend #{requested}.") unless requested == TREE_SITTER_BACKEND.id
|
|
25
|
+
|
|
26
|
+
type_script_feature_profile.merge(
|
|
27
|
+
backend: requested,
|
|
28
|
+
backend_ref: TREE_SITTER_BACKEND.to_h,
|
|
29
|
+
supports_dialects: true
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def type_script_plan_context(backend: nil)
|
|
34
|
+
profile = type_script_backend_feature_profile(backend: backend)
|
|
35
|
+
return profile if profile[:ok] == false
|
|
36
|
+
|
|
37
|
+
{
|
|
38
|
+
family_profile: type_script_feature_profile,
|
|
39
|
+
feature_profile: {
|
|
40
|
+
backend: profile[:backend],
|
|
41
|
+
supports_dialects: true,
|
|
42
|
+
supported_policies: profile[:supported_policies]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def parse_type_script(source, dialect)
|
|
48
|
+
requested = TREE_SITTER_BACKEND.id
|
|
49
|
+
return unsupported_feature_result("Unsupported TypeScript backend #{requested}.") unless requested == TREE_SITTER_BACKEND.id
|
|
50
|
+
return analyze_type_script_module(source) if dialect == "typescript"
|
|
51
|
+
|
|
52
|
+
{ ok: false, diagnostics: [{ severity: "error", category: "unsupported_feature", message: "Unsupported TypeScript dialect #{dialect}." }], policies: [] }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def match_type_script_owners(template, destination)
|
|
56
|
+
destination_paths = destination[:owners].to_h { |owner| [owner[:path], true] }
|
|
57
|
+
template_paths = template[:owners].to_h { |owner| [owner[:path], true] }
|
|
58
|
+
{
|
|
59
|
+
matched: template[:owners].filter { |owner| destination_paths[owner[:path]] }.map { |owner| { template_path: owner[:path], destination_path: owner[:path] } },
|
|
60
|
+
unmatched_template: template[:owners].map { |owner| owner[:path] }.reject { |path| destination_paths[path] },
|
|
61
|
+
unmatched_destination: destination[:owners].map { |owner| owner[:path] }.reject { |path| template_paths[path] }
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def merge_type_script(template_source, destination_source, dialect)
|
|
66
|
+
template = parse_type_script(template_source, dialect)
|
|
67
|
+
return { ok: false, diagnostics: template[:diagnostics], policies: [] } unless template[:ok]
|
|
68
|
+
destination = parse_type_script(destination_source, dialect)
|
|
69
|
+
unless destination[:ok]
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
diagnostics: destination[:diagnostics].map { |diagnostic| diagnostic[:category] == "parse_error" ? diagnostic.merge(category: "destination_parse_error") : diagnostic },
|
|
73
|
+
policies: []
|
|
74
|
+
}
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
destination_declarations = destination.dig(:analysis, :declarations).to_h { |item| [item[:path], item] }
|
|
78
|
+
merged_declaration_texts = destination.dig(:analysis, :declarations).map { |item| item[:text] } +
|
|
79
|
+
template.dig(:analysis, :declarations).reject { |item| destination_declarations[item[:path]] }.map { |item| item[:text] }
|
|
80
|
+
import_block = destination.dig(:analysis, :imports).map { |item| item[:text] }.join
|
|
81
|
+
declaration_block = merged_declaration_texts.join("\n").rstrip
|
|
82
|
+
sections = [import_block.rstrip, declaration_block].reject(&:empty?)
|
|
83
|
+
|
|
84
|
+
{ ok: true, diagnostics: [], output: "#{sections.join("\n\n").rstrip}\n", policies: [DESTINATION_WINS_ARRAY_POLICY] }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def analyze_type_script_module(source)
|
|
88
|
+
parsed = TreeHaver.parse_with_language_pack(TreeHaver::ParserRequest.new(source: source, language: "typescript", dialect: "typescript"))
|
|
89
|
+
return { ok: false, diagnostics: parsed[:diagnostics], policies: [] } unless parsed[:ok]
|
|
90
|
+
processed = TreeHaver.process_with_language_pack(TreeHaver::ProcessRequest.new(source: source, language: "typescript"))
|
|
91
|
+
return { ok: false, diagnostics: processed[:diagnostics], policies: [] } unless processed[:ok]
|
|
92
|
+
|
|
93
|
+
imports = processed[:analysis].imports.each_with_index.map do |item, index|
|
|
94
|
+
{ path: "/imports/#{index}", match_key: item.source, text: import_text(source, item.span) }
|
|
95
|
+
end
|
|
96
|
+
declarations = processed[:analysis].structure
|
|
97
|
+
.select { |item| item.name }
|
|
98
|
+
.map { |item| { path: "/declarations/#{item.name}", match_key: item.name, text: declaration_text(source, item.span) } }
|
|
99
|
+
.sort_by { |item| item[:path] }
|
|
100
|
+
|
|
101
|
+
{
|
|
102
|
+
ok: true,
|
|
103
|
+
diagnostics: [],
|
|
104
|
+
analysis: {
|
|
105
|
+
kind: "typescript",
|
|
106
|
+
dialect: "typescript",
|
|
107
|
+
source: source,
|
|
108
|
+
owners: imports.map { |item| { path: item[:path], owner_kind: "import", match_key: item[:match_key] } } +
|
|
109
|
+
declarations.map { |item| { path: item[:path], owner_kind: "declaration", match_key: item[:match_key] } },
|
|
110
|
+
imports: imports,
|
|
111
|
+
declarations: declarations
|
|
112
|
+
},
|
|
113
|
+
policies: []
|
|
114
|
+
}
|
|
115
|
+
end
|
|
116
|
+
private_class_method :analyze_type_script_module
|
|
117
|
+
|
|
118
|
+
def import_text(source, span)
|
|
119
|
+
"#{slice_span(source, span)}\n"
|
|
120
|
+
end
|
|
121
|
+
private_class_method :import_text
|
|
122
|
+
|
|
123
|
+
def declaration_text(source, span)
|
|
124
|
+
"#{line_anchored_slice(source, span)}\n"
|
|
125
|
+
end
|
|
126
|
+
private_class_method :declaration_text
|
|
127
|
+
|
|
128
|
+
def slice_span(source, span)
|
|
129
|
+
source[span.start_byte...span.end_byte].strip
|
|
130
|
+
end
|
|
131
|
+
private_class_method :slice_span
|
|
132
|
+
|
|
133
|
+
def line_anchored_slice(source, span)
|
|
134
|
+
line_start = source.rindex("\n", [span.start_byte - 1, 0].max)
|
|
135
|
+
line_start = line_start ? line_start + 1 : 0
|
|
136
|
+
source[line_start...span.end_byte].strip
|
|
137
|
+
end
|
|
138
|
+
private_class_method :line_anchored_slice
|
|
139
|
+
|
|
140
|
+
def unsupported_feature_result(message)
|
|
141
|
+
Ast::Merge.unsupported_feature_result(message)
|
|
142
|
+
end
|
|
143
|
+
private_class_method :unsupported_feature_result
|
|
144
|
+
end
|
|
145
|
+
end
|
data.tar.gz.sig
ADDED
|
Binary file
|
metadata
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: typescript-merge
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 7.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Peter H. Boling
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain:
|
|
10
|
+
- |
|
|
11
|
+
-----BEGIN CERTIFICATE-----
|
|
12
|
+
MIIEgDCCAuigAwIBAgIBATANBgkqhkiG9w0BAQsFADBDMRUwEwYDVQQDDAxwZXRl
|
|
13
|
+
ci5ib2xpbmcxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkW
|
|
14
|
+
A2NvbTAeFw0yNTA1MDQxNTMzMDlaFw00NTA0MjkxNTMzMDlaMEMxFTATBgNVBAMM
|
|
15
|
+
DHBldGVyLmJvbGluZzEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPy
|
|
16
|
+
LGQBGRYDY29tMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAruUoo0WA
|
|
17
|
+
uoNuq6puKWYeRYiZekz/nsDeK5x/0IEirzcCEvaHr3Bmz7rjo1I6On3gGKmiZs61
|
|
18
|
+
LRmQ3oxy77ydmkGTXB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GuqQZVH9IBD1i9K6aSs7pT6TW8itXUIlkIUI2tg5YzW6OFfPzq
|
|
33
|
+
QekSkX3lZfY+HTSp/o+YvKkqWLUV7PQ7xh1ZYDtocpaHwgxe/j3bBqHE+CUPH2vA
|
|
34
|
+
0V/FwdTRWcwsjVoOJTrYcff8pBZ8r2MvtAc54xfnnhGFzeRHfcltobgFxkAXdE6p
|
|
35
|
+
DVjBtqT23eugOqQ73umLcYDZkc36vnqGxUBSsXrzY9pzV5gGr2I8YUxMqf6ATrZt
|
|
36
|
+
L9nRqA==
|
|
37
|
+
-----END CERTIFICATE-----
|
|
38
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
39
|
+
dependencies:
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: ast-merge
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - '='
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 7.0.0
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - '='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 7.0.0
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: tree_haver
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - '='
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: 7.0.0
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - '='
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 7.0.0
|
|
68
|
+
description: Portable TypeScript module owner analysis and merge behavior for Structured
|
|
69
|
+
Merge.
|
|
70
|
+
email:
|
|
71
|
+
- info@structuredmerge.org
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- lib/typescript-merge.rb
|
|
77
|
+
- lib/typescript/merge.rb
|
|
78
|
+
- lib/typescript/merge/version.rb
|
|
79
|
+
homepage: https://github.com/structuredmerge/structuredmerge-ruby
|
|
80
|
+
licenses:
|
|
81
|
+
- AGPL-3.0-only
|
|
82
|
+
- PolyForm-Small-Business-1.0.0
|
|
83
|
+
metadata:
|
|
84
|
+
homepage_uri: https://structuredmerge.org
|
|
85
|
+
source_code_uri: https://github.com/structuredmerge/structuredmerge-ruby/tree/v7.0.0
|
|
86
|
+
changelog_uri: https://github.com/structuredmerge/structuredmerge-ruby/blob/v7.0.0/CHANGELOG.md
|
|
87
|
+
bug_tracker_uri: https://github.com/structuredmerge/structuredmerge-ruby/issues
|
|
88
|
+
documentation_uri: https://www.rubydoc.info/gems/typescript-merge/7.0.0
|
|
89
|
+
funding_uri: https://github.com/sponsors/pboling
|
|
90
|
+
wiki_uri: https://github.com/structuredmerge/structuredmerge-ruby/wiki
|
|
91
|
+
discord_uri: https://discord.gg/3qme4XHNKN
|
|
92
|
+
rubygems_mfa_required: 'true'
|
|
93
|
+
rdoc_options: []
|
|
94
|
+
require_paths:
|
|
95
|
+
- lib
|
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
|
+
requirements:
|
|
98
|
+
- - ">="
|
|
99
|
+
- !ruby/object:Gem::Version
|
|
100
|
+
version: 4.0.0
|
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
|
+
requirements:
|
|
103
|
+
- - ">="
|
|
104
|
+
- !ruby/object:Gem::Version
|
|
105
|
+
version: '0'
|
|
106
|
+
requirements: []
|
|
107
|
+
rubygems_version: 4.0.10
|
|
108
|
+
specification_version: 4
|
|
109
|
+
summary: Structured Merge TypeScript module analysis and merge for Ruby
|
|
110
|
+
test_files: []
|
metadata.gz.sig
ADDED