dianping/cat · warning · StaticWarning

W01

W01

Error message

Avoid this type of import. Use import module namespace instead

What it means

W01 is a lint-level StaticWarning, not a spec error. The worker's addNamespace() emits it when a module import arrives with an empty prefix (type === 'module' && prefix === ''), i.e. an 'import module' written without a namespace prefix binding. The recommendation is to always use 'import module namespace prefix = "uri"' so imported functions/variables have an explicit, addressable prefix.

Source

Thrown at cat-home/src/main/webapp/assets/js/editor/worker-xquery.js:1801

                    }
                    if(mod.functions) {
                        TreeOps.concat(this.functions, mod.functions);
                    }
                } catch(e) {
                    throw new StaticError('XQST0059', 'module "' + uri + '" not found', pos);
                }
            }
            return this;
        },
        getAvailableModuleNamespaces: function(){
            return this.root.availableModuleNamespaces;
        },
        getPrefixByNamespace: function(uri){
            return this.root.namespaces[uri].prefix;
        },
        addNamespace: function (uri, prefix, pos, type) {
            if(prefix === '' && type === 'module') {
                throw new StaticWarning('W01', 'Avoid this type of import. Use import module namespace instead', pos);
            }
            if (uri === '') {
                throw new StaticError('XQST0088', 'empty target namespace in module import or module declaration', pos);
            }
            var namespace = this.getNamespace(uri);
            if (namespace && namespace.type === type && type !== 'declare' && !namespace.override) {
                throw new StaticError('XQST0047', '"' + uri + '": duplicate target namespace', pos);
            }
            namespace = this.getNamespaceByPrefix(prefix);
            if (namespace && !namespace.override) {
                throw new StaticError('XQST0033', '"' + prefix + '": namespace prefix already bound to "' + namespace.uri + '"', pos);
            }

            namespace = this.namespaces[uri];
            this.namespaces[uri] = {
                prefix: prefix,
                pos: pos,
                type: type

View on GitHub (pinned to e815e74d4c)

Solutions

  1. Rewrite the import as 'import module namespace p = "URI";' with an explicit prefix.
  2. Use the prefix when calling the module's functions (p:func(...)) so names resolve unambiguously.
  3. Treat it as advisory: warnings do not abort compilation, but fix them to keep static analysis (prefix expansion, XPST0081 checks) accurate.

Example fix

// before
import module "http://example.org/mod";

// after
import module namespace m = "http://example.org/mod";
Defensive patterns

Strategy: validation

Validate before calling

// Reject unprefixed module imports before sending source to the worker
if (/import\s+module\s+["']/.test(queryText)) {
  warn('Use: import module namespace prefix = "URI";');
}

Try / catch

if (e.name === 'StaticWarning' && e.code === 'W01') {
  reportLint(e.pos, e.message); // non-fatal
}

Prevention

When it happens

Trigger: Any module import parsed with prefix '' — e.g. a construct like 'import module default-element-namespace style' or a parser state that yields no prefix for the module import. addNamespace(uri, '', pos, 'module') triggers it immediately.

Common situations: Hand-written queries that rely on a default namespace instead of explicit prefixes; code migrated from XQuery processors that tolerate unprefixed module imports; generated code that omits the namespace clause.

Related errors


AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14). Data as JSON: /api/errors/0defc4d0d075142a. Report an issue: GitHub.