@nudojs/parser 1.4.22 → 1.4.24

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.
package/dist/index.d.ts CHANGED
@@ -217,6 +217,14 @@ declare function extractDirectivesQuiet(ast: Node): FunctionWithDirectives[];
217
217
  * runWithDirectiveDiags 域(无则丢弃,纯查询形态)。
218
218
  */
219
219
  declare function extractInlineDirectives(node: Node, opts?: ExtractDirectivesOpts): InlineDirective[];
220
- declare function extractFileDirectives(ast: Node): FileDirective[];
220
+ /**
221
+ * 从 AST 抽文件级指令(`@nudo:env` / `@nudo:mock-module`,只认行注释)。
222
+ *
223
+ * `diags`:调用方自备的诊断累积数组——JSDoc/块注释内错位的文件级指令族
224
+ * 标签发 nudo:directive-syntax 警告(单次调用内同文案去重)。不传时为
225
+ * 纯查询形态:诊断丢弃;若外层有 runWithDirectiveDiags 活动域,则落入
226
+ * 该域并与其共享去重。
227
+ */
228
+ declare function extractFileDirectives(ast: Node, opts?: ExtractDirectivesOpts): FileDirective[];
221
229
 
222
230
  export { type AsDirective, type CaseDirective, type Directive, type DirectiveDiag, type EnvDirective, type ExtractDirectivesOpts, type FileDirective, type FunctionWithDirectives, type InlineDirective, type InstanceMethod, type MockDirective, type MockModuleDirective, type PureDirective, type ReplaceDirective, type SampleDirective, type SinonExpression, type SkipDirective, asAssignmentExpression, asExpression, asIdentifier, asMemberExpression, asProgram, classIdName, classInstanceMethods, classMemberKey, classMemberKeyName, exportSpecifierExportedName, exportSpecifierLocalName, extractDirectives, extractDirectivesQuiet, extractFileDirectives, extractInlineDirectives, fnOrClassIdLoc, fnOrClassIdName, getClassMembers, getDeclarations, getDeclaratorId, getDeclaratorInit, getExportDeclaration, getExportSpecifiers, getExpressionStatementExpression, getFirstDeclaratorId, identifierName, isModuleExportsMember, memberObjectName, memberPropertyKey, memberPropertyName, methodFunctionNode, nameOrStringValue, paramDisplayName, paramName, parse, parseCaseArgExpr, programBody, runWithDirectiveDiags, unwrapDefaultExport, unwrapExport };
package/dist/index.js CHANGED
@@ -1117,11 +1117,37 @@ function findReplaceSeparator(raw) {
1117
1117
  }
1118
1118
  var ENV_REGEX = /^\/?\s*@nudo:env\s+(.+)/;
1119
1119
  var MOCK_MODULE_REGEX = /^\/?\s*@nudo:mock-module\s+(.+)/;
1120
- function extractFileDirectives(ast) {
1120
+ var FILE_TAG_IN_BLOCK_REGEX = /(?:^|\n)[ \t]*(?:\*[ \t]*)?@nudo:(env|mock-module)\b/g;
1121
+ function warnMisplacedFileTags(blockText) {
1122
+ FILE_TAG_IN_BLOCK_REGEX.lastIndex = 0;
1123
+ let m;
1124
+ while (m = FILE_TAG_IN_BLOCK_REGEX.exec(blockText)) {
1125
+ const tag = m[1];
1126
+ emitDirectiveDiag({
1127
+ code: "nudo:directive-syntax",
1128
+ message: tag === "env" ? `@nudo:env is a file-level directive \u2014 use '/// @nudo:env node' at the top of the file (JSDoc block form is ignored)` : `@nudo:mock-module is a file-level directive \u2014 use '/// @nudo:mock-module "fs" from "./mock-fs.js"' at the top of the file (JSDoc block form is ignored)`
1129
+ });
1130
+ }
1131
+ }
1132
+ function extractFileDirectives(ast, opts) {
1133
+ if (!opts?.diags) return collectFileDirectives(ast);
1134
+ const prev = activeDiagSink;
1135
+ activeDiagSink = { list: opts.diags, seen: /* @__PURE__ */ new Set() };
1136
+ try {
1137
+ return collectFileDirectives(ast);
1138
+ } finally {
1139
+ activeDiagSink = prev;
1140
+ }
1141
+ }
1142
+ function collectFileDirectives(ast) {
1121
1143
  const results = [];
1122
1144
  if (ast.type !== "File") return results;
1123
1145
  const comments = ast.comments ?? [];
1124
1146
  for (const comment of comments) {
1147
+ if (comment.type === "CommentBlock") {
1148
+ warnMisplacedFileTags(comment.value);
1149
+ continue;
1150
+ }
1125
1151
  if (comment.type !== "CommentLine") continue;
1126
1152
  const text = comment.value;
1127
1153
  const mockModuleMatch = text.match(MOCK_MODULE_REGEX);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nudojs/parser",
3
- "version": "1.4.22",
3
+ "version": "1.4.24",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },
@@ -39,7 +39,7 @@
39
39
  "registry": "https://registry.npmjs.org"
40
40
  },
41
41
  "dependencies": {
42
- "@nudojs/core": "1.13.0",
42
+ "@nudojs/core": "1.14.1",
43
43
  "@babel/types": "^8.0.6"
44
44
  },
45
45
  "scripts": {