Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -981,12 +981,23 @@ public class ExportSwift {
rawValue = stringLiteral.segments.first?.as(StringSegmentSyntax.self)?.content.text
} else if let boolLiteral = element.rawValue?.value.as(BooleanLiteralExprSyntax.self) {
rawValue = boolLiteral.literal.text
} else if let intLiteral = element.rawValue?.value.as(IntegerLiteralExprSyntax.self) {
rawValue = intLiteral.literal.text
} else if let floatLiteral = element.rawValue?.value.as(FloatLiteralExprSyntax.self) {
rawValue = floatLiteral.literal.text
} else {
rawValue = nil
var numericExpr = element.rawValue?.value
var isNegative = false
if let prefixExpr = numericExpr?.as(PrefixOperatorExprSyntax.self),
prefixExpr.operator.text == "-"
{
numericExpr = prefixExpr.expression
isNegative = true
}

if let intLiteral = numericExpr?.as(IntegerLiteralExprSyntax.self) {
rawValue = isNegative ? "-\(intLiteral.literal.text)" : intLiteral.literal.text
} else if let floatLiteral = numericExpr?.as(FloatLiteralExprSyntax.self) {
rawValue = isNegative ? "-\(floatLiteral.literal.text)" : floatLiteral.literal.text
} else {
rawValue = nil
}
}
} else {
rawValue = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}

@JS enum Priority: Int32 {
case lowest = 1
case lowest = -1
case low = 2
case medium = 3
case high = 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export enum TSHttpStatus {
}

export const PriorityValues: {
readonly Lowest: 1;
readonly Lowest: -1;
readonly Low: 2;
readonly Medium: 3;
readonly High: 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const TSHttpStatus = {
};

export const PriorityValues = {
Lowest: 1,
Lowest: -1,
Low: 2,
Medium: 3,
High: 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@

],
"name" : "lowest",
"rawValue" : "1"
"rawValue" : "-1"
},
{
"associatedValues" : [
Expand Down
1 change: 1 addition & 0 deletions Tests/BridgeJSRuntimeTests/ExportAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ struct TestError: Error {
case ok = 200
case notFound = 404
case serverError = 500
case unknown = -1
}

@JS(enumStyle: .tsEnum) enum TSDirection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,13 @@
],
"name" : "serverError",
"rawValue" : "500"
},
{
"associatedValues" : [

],
"name" : "unknown",
"rawValue" : "-1"
}
],
"emitStyle" : "const",
Expand Down
1 change: 1 addition & 0 deletions Tests/prelude.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) {
assert.equal(exports.HttpStatus.Ok, 200);
assert.equal(exports.HttpStatus.NotFound, 404);
assert.equal(HttpStatusValues.ServerError, 500);
assert.equal(HttpStatusValues.Unknown, -1);

assert.equal(exports.setTheme(exports.Theme.Light), exports.Theme.Light);
assert.equal(exports.setTheme(exports.Theme.Dark), exports.Theme.Dark);
Expand Down