Skip to content

Commit e9c5d20

Browse files
committed
fix: mainThread case
1 parent cb106b8 commit e9c5d20

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

lib/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ function generateDartWithWorker(content, path, script) {
124124
resolve({ result: result, error: error })
125125
})
126126
} else {
127+
isPartOfFile = path.endsWith(dnPartExtension) && !path.endsWith(`0.${dnPartExtension}`)
127128
const worker = new Worker(script, {
128-
workerData: { content: content },
129+
workerData: { content: content, isPartOfFile: isPartOfFile },
129130
resourceLimits: { maxOldGenerationSizeMb: 8 * 1024 }
130131
})
131132
worker.on("message", resolve)
@@ -151,7 +152,7 @@ function generateDartWithWorker(content, path, script) {
151152

152153
function splitCodeFileIfNeed(separator, maxLength, path) {
153154
const content = rf.readFileSync(path, "utf-8")
154-
if (content.length > maxLength) {
155+
if (!this.isMainThread && isSupportWorkerThreads && content.length > maxLength) {
155156
let components = content.split(separator)
156157
return components.map((c, i) => {
157158
if (i == components.length - 1) {

lib/objc/DNObjectiveCContext.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,15 +576,19 @@ class DNImportContext extends DNContext {
576576
}
577577

578578
class DNRootContext extends DNContext {
579-
constructor(internal, needExport) {
579+
constructor(internal, needExport, isPartOfFile = false) {
580580
super(internal)
581581
this.needExport = needExport
582+
this.isPartOfFile = isPartOfFile
582583
}
583584

584585
parse() {
585-
var result = '// Generated by @dartnative/codegen:\n// https://www.npmjs.com/package/@dartnative/codegen\n\n'
586+
var result = ''
587+
if (!this.isPartOfFile) {
588+
result += '// Generated by @dartnative/codegen:\n// https://www.npmjs.com/package/@dartnative/codegen\n\n'
589+
}
586590
var packageSet = new Set()
587-
if (!this.needExport) {
591+
if (!this.needExport && !this.isPartOfFile) {
588592
result += "import 'dart:ffi';\n\n"
589593
result += "import 'package:dart_native/dart_native.dart';\n"
590594
result += "import 'package:dart_native_gen/dart_native_gen.dart';\n"

lib/objc/DNObjectiveCConverter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function convert(content, cb) {
2626
if (!cb) {
2727
cb = callback
2828
}
29+
2930
try {
3031
const chars = new antlr4.InputStream(content)
3132
const lexer = new ObjectiveCLexer(chars)
@@ -36,7 +37,8 @@ function convert(content, cb) {
3637
const parser = new ObjectiveCParser(tokens)
3738
parser.addErrorListener(errorListener)
3839
const tree = parser.translationUnit()
39-
const listener = new DNObjectiveCParserListener(cb)
40+
let isPartOfFile = workerData ? workerData.isPartOfFile : false
41+
const listener = new DNObjectiveCParserListener(cb, isPartOfFile)
4042
antlr4.tree.ParseTreeWalker.DEFAULT.walk(listener, tree)
4143
} catch (e) {
4244
cb(null, e)

lib/objc/DNObjectiveCParserListener.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ let DNRootContext = c.DNRootContext,
2020

2121
// This class defines a complete listener for a parse tree produced by ObjectiveCParser.
2222
class DNObjectiveCParserListener extends ObjectiveCParserListener {
23-
constructor(cb) {
23+
constructor(cb, isPartOfFile) {
2424
super()
2525
ObjectiveCParserListener.call(this)
2626
//success callack
2727
this.cb = cb
28+
this.isPartOfFile = isPartOfFile
2829
}
2930

3031
buildDart() {
@@ -45,7 +46,7 @@ class DNObjectiveCParserListener extends ObjectiveCParserListener {
4546
}
4647
}
4748
}
48-
this.rootContext = new DNRootContext(ctx, this.needExport)
49+
this.rootContext = new DNRootContext(ctx, this.needExport, this.isPartOfFile)
4950
this.currentContext = this.rootContext
5051
}
5152
// Exit a parse tree produced by ObjectiveCParser#translationUnit.

0 commit comments

Comments
 (0)