Skip to content

ArgToken (EN)

bhsd edited this page Jun 10, 2024 · 10 revisions
Table of Contents

Other Languages

Introduction

Template arguments wrapped in {{{}}}.

✅ Available in the Mini and Browser versions.

Properties

default

✅ Expand

type: string | false
Default value.

// default
var {firstChild} = Parser.parse('{{{a}}}');
assert.equal(firstChild, '{{{a}}}');
assert.strictEqual(firstChild.default, false);
// default (main)
var {firstChild} = Parser.parse('{{{a}}}');
firstChild.default = 'b';
assert.equal(firstChild, '{{{a|b}}}');

name

Expand

type: string
Name of the argument, read-only.

// name (main)
var {firstChild} = Parser.parse('{{{a}}}'),
	argName = firstChild.firstChild;
assert.equal(firstChild, '{{{a}}}');
assert.strictEqual(firstChild.name, 'a');
argName.replaceChildren('b');
assert.strictEqual(firstChild.name, 'b');

Methods

lint

✅ Expand

returns: LintError[]
Report potential grammar errors.

// lint
var noinclude = Parser.parse('{{{a}}}').firstChild,
	include = Parser.parse('{{{a|b|c}}}', true).firstChild;
assert.equal(noinclude, '{{{a}}}');
assert.deepEqual(noinclude.lint(), [
	{
		rule: 'no-arg',
		severity: 'error',
		message: 'unexpected template argument',
		startLine: 0,
		startCol: 0,
		startIndex: 0,
		endLine: 0,
		endCol: 7,
		endIndex: 7,
	},
]);
assert.equal(include, '{{{a|b|c}}}');
assert.deepEqual(include.lint(), [
	{
		rule: 'no-ignored',
		severity: 'error',
		message: 'invisible content inside triple braces',
		startLine: 0,
		startCol: 6,
		startIndex: 6,
		endLine: 0,
		endCol: 8,
		endIndex: 8,
		suggestions: [
			{
				desc: 'remove',
				range: [6, 8],
				text: '',
			},
			{
				desc: 'escape',
				range: [6, 7],
				text: '{{!}}',
			},
		],
	},
]);

cloneNode

Expand

returns: this
Deep clone the node.

// cloneNode (main)
var {firstChild} = Parser.parse('{{{a}}}');
assert.equal(firstChild, '{{{a}}}');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);

removeRedundant

Expand

Remove redundant parts.

// removeRedundant (main)
var {firstChild} = Parser.parse('{{{a|b|c}}}');
assert.equal(firstChild, '{{{a|b|c}}}');
firstChild.removeRedundant();
assert.equal(firstChild, '{{{a|b}}}');

setName

Expand

param: string new argument name
Set the argument name.

// setName (main)
var {firstChild} = Parser.parse('{{{a}}}');
assert.equal(firstChild, '{{{a}}}');
firstChild.setName('b');
assert.equal(firstChild, '{{{b}}}');

setDefault

Expand

param: string
Set the default value.

// setDefault (main)
var {firstChild} = Parser.parse('{{{a}}}');
assert.equal(firstChild, '{{{a}}}');
firstChild.setDefault('b');
assert.equal(firstChild, '{{{a|b}}}');
Clone this wiki locally