klenod-plugin-javascript 0.0.13 → 0.0.14
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bec41fc4fdb0a5e8767cef857e2e59516fa26f95f9c24c8a8889dd25010885c1
|
|
4
|
+
data.tar.gz: a3f660de08c2bf94173cd16c8aa8552427bea2b1d91a611243e9b8b6ac80867f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5526827d67e6c8ef371e693399c7093f77cd2a3e2ca5f93e1ceb12688973185e8de4832feb0f9216a7c320a6b849476ccbead6f90fc087d5f2b604c8d30df070
|
|
7
|
+
data.tar.gz: 4f691c8f0d52eb5f901e003a9a3a6334837a1123be320a215aa7223fd12efaf7823b3b623581d3bdbca2b4e87e1b8af7193ccb1a85449034e04342b563e5042d
|
data/ext/native/Cargo.lock
CHANGED
|
@@ -964,9 +964,9 @@ dependencies = [
|
|
|
964
964
|
|
|
965
965
|
[[package]]
|
|
966
966
|
name = "swc_core"
|
|
967
|
-
version = "
|
|
967
|
+
version = "78.0.0"
|
|
968
968
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
969
|
-
checksum = "
|
|
969
|
+
checksum = "2b3e1cf21711152ac57d0ade1fea33bf8f1cc974f7bc1f668ac0252252876803"
|
|
970
970
|
dependencies = [
|
|
971
971
|
"swc_allocator",
|
|
972
972
|
"swc_atoms",
|
data/ext/native/Cargo.toml
CHANGED
|
@@ -9,4 +9,4 @@ crate-type = ["cdylib"]
|
|
|
9
9
|
|
|
10
10
|
[dependencies]
|
|
11
11
|
magnus = "0.8.2"
|
|
12
|
-
swc_core = { version = "
|
|
12
|
+
swc_core = { version = "78.0.0", features = ["common", "ecma_ast", "ecma_codegen", "ecma_parser", "ecma_parser_typescript", "ecma_transforms_react", "ecma_transforms_typescript", "ecma_visit"] }
|
data/ext/native/src/lib.rs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
use magnus::{function, prelude::*, Error, RArray, RHash, Ruby, TryConvert};
|
|
2
2
|
use swc_core::{
|
|
3
3
|
common::{
|
|
4
|
-
comments::NoopComments, sync::Lrc, FileName, Globals, Mark, SourceMap, Span,
|
|
4
|
+
comments::NoopComments, sync::Lrc, FileName, Globals, Mark, SourceMap, Span, Spanned,
|
|
5
|
+
GLOBALS,
|
|
5
6
|
},
|
|
6
7
|
ecma::{
|
|
7
8
|
ast::{
|
|
@@ -222,9 +223,16 @@ fn parse_module(
|
|
|
222
223
|
);
|
|
223
224
|
let mut parser = Parser::new_from(lexer);
|
|
224
225
|
let module = parser.parse_module().map_err(|error| {
|
|
226
|
+
let loc = source_map.lookup_char_pos(error.span().lo);
|
|
225
227
|
Error::new(
|
|
226
228
|
ruby.exception_syntax_error(),
|
|
227
|
-
format!(
|
|
229
|
+
format!(
|
|
230
|
+
"{}:{}:{}: {}",
|
|
231
|
+
filename,
|
|
232
|
+
loc.line,
|
|
233
|
+
loc.col.0 + 1,
|
|
234
|
+
error.kind().msg()
|
|
235
|
+
),
|
|
228
236
|
)
|
|
229
237
|
})?;
|
|
230
238
|
Ok(ParsedProgram {
|
|
@@ -12,6 +12,7 @@ require "klenod/build/source_map"
|
|
|
12
12
|
require "klenod/build/transform_result"
|
|
13
13
|
require "klenod/runtime"
|
|
14
14
|
|
|
15
|
+
require_relative "../../plugin/javascript/errors"
|
|
15
16
|
require_relative "../../plugin/javascript/parser"
|
|
16
17
|
|
|
17
18
|
module Klenod
|
|
@@ -73,13 +74,18 @@ module Klenod
|
|
|
73
74
|
|
|
74
75
|
custom_element = custom_element_module?(module_id)
|
|
75
76
|
jsx_runtime_namespace = custom_element ? jsx_runtime_namespace(module_id) : nil
|
|
76
|
-
transform =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
transform =
|
|
78
|
+
begin
|
|
79
|
+
Parser.transform(
|
|
80
|
+
code,
|
|
81
|
+
filename: module_id.to_s,
|
|
82
|
+
source_kind: source_kind(module_id),
|
|
83
|
+
minify: minify_enabled?(context),
|
|
84
|
+
jsx_runtime_namespace: jsx_runtime_namespace
|
|
85
|
+
)
|
|
86
|
+
rescue ScriptError => e
|
|
87
|
+
raise ParseError.new(e, source: code, module_id: module_id)
|
|
88
|
+
end
|
|
83
89
|
javascript_source, imports =
|
|
84
90
|
if custom_element
|
|
85
91
|
inject_jsx_runtime(transform.code, transform.imports, module_id, jsx_runtime_namespace)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "klenod/build/source_error"
|
|
4
|
+
|
|
5
|
+
module Klenod
|
|
6
|
+
module Build
|
|
7
|
+
module Plugins
|
|
8
|
+
module JavaScriptPlugin
|
|
9
|
+
# The native parser raises a bare SyntaxError, which is a ScriptError
|
|
10
|
+
# rather than a StandardError, so it escapes every `rescue => e` in the
|
|
11
|
+
# build and takes the watcher thread down with it. Wrapping it in a
|
|
12
|
+
# SourceError that carries the source lets it be collected like a Haml
|
|
13
|
+
# parse error and rendered in the browser error dialog.
|
|
14
|
+
class ParseError < Klenod::Build::SourceError
|
|
15
|
+
# "app:/pages/thing.tsx:33:9: Expected '</', got ':'"
|
|
16
|
+
LOCATION = /\A(?<file>.+?):(?<line>\d+):(?<column>\d+):\s*(?<message>.*)\z/m
|
|
17
|
+
|
|
18
|
+
def kind
|
|
19
|
+
"JavaScript parse error"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def location(error)
|
|
25
|
+
found = LOCATION.match(error.message)
|
|
26
|
+
return nil unless found
|
|
27
|
+
|
|
28
|
+
# One-based, matching HamlPlugin::ParseError#line and the column the
|
|
29
|
+
# native parser reports.
|
|
30
|
+
Location.new(
|
|
31
|
+
line: found[:line].to_i,
|
|
32
|
+
column: found[:column].to_i,
|
|
33
|
+
detail: found[:message]
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: klenod-plugin-javascript
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.14
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrés Alin
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.0.
|
|
18
|
+
version: 0.0.14
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.0.
|
|
25
|
+
version: 0.0.14
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: rb_sys
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -68,6 +68,7 @@ files:
|
|
|
68
68
|
- lib/klenod/build/plugins/node_modules_plugin.rb
|
|
69
69
|
- lib/klenod/build/plugins/node_modules_plugin/package_exports.rb
|
|
70
70
|
- lib/klenod/plugin/javascript.rb
|
|
71
|
+
- lib/klenod/plugin/javascript/errors.rb
|
|
71
72
|
- lib/klenod/plugin/javascript/parser.rb
|
|
72
73
|
- lib/klenod/plugin/javascript/version.rb
|
|
73
74
|
homepage: https://github.com/aalin/klenod
|