How to use @vue/shared - 10 common examples

To help you get started, we’ve selected a few @vue/shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuejs / vue-next / packages / compiler-dom / __tests__ / transforms / vHtml.spec.ts View on Github external
it('should raise error and ignore children when v-html is present', () => {
    const onError = jest.fn()
    const ast = transformWithVHtml(`<div>hello</div>`, {
      onError
    })
    expect(onError.mock.calls).toMatchObject([
      [{ code: DOMErrorCodes.X_V_HTML_WITH_CHILDREN }]
    ])
    expect((ast.children[0] as PlainElementNode).codegenNode).toMatchObject({
      arguments: [
        `"div"`,
        createObjectMatcher({
          innerHTML: `[test]`
        }),
        `null`, // &lt;-- children should have been removed
        genFlagText(PatchFlags.PROPS),
        `["innerHTML"]`
      ]
    })
  })
github vuejs / vue-next / packages / compiler-core / __tests__ / transforms / transformElement.spec.ts View on Github external
test('TEXT', () =&gt; {
      const { node } = parseWithBind(`<div>foo</div>`)
      expect(node.arguments.length).toBe(3)

      const { node: node2 } = parseWithBind(`<div>{{ foo }}</div>`)
      expect(node2.arguments.length).toBe(4)
      expect(node2.arguments[3]).toBe(genFlagText(PatchFlags.TEXT))

      // multiple nodes, merged with optimize text
      const { node: node3 } = parseWithBind(`<div>foo {{ bar }} baz</div>`)
      expect(node3.arguments.length).toBe(4)
      expect(node3.arguments[3]).toBe(genFlagText(PatchFlags.TEXT))
    })
github vuejs / vue-next / packages / compiler-core / __tests__ / transforms / transformElement.spec.ts View on Github external
test('TEXT', () =&gt; {
      const { node } = parseWithBind(`<div>foo</div>`)
      expect(node.arguments.length).toBe(3)

      const { node: node2 } = parseWithBind(`<div>{{ foo }}</div>`)
      expect(node2.arguments.length).toBe(4)
      expect(node2.arguments[3]).toBe(genFlagText(PatchFlags.TEXT))

      // multiple nodes, merged with optimize text
      const { node: node3 } = parseWithBind(`<div>foo {{ bar }} baz</div>`)
      expect(node3.arguments.length).toBe(4)
      expect(node3.arguments[3]).toBe(genFlagText(PatchFlags.TEXT))
    })
github vuejs / vue-next / packages / compiler-core / __tests__ / transforms / transformElement.spec.ts View on Github external
}
    })
    expect(node.callee).toBe(CREATE_VNODE)
    expect(node.arguments[1]).toMatchObject({
      type: NodeTypes.JS_OBJECT_EXPRESSION,
      properties: [
        {
          type: NodeTypes.JS_PROPERTY,
          key: _dir!.arg,
          value: _dir!.exp
        }
      ]
    })
    // should factor in props returned by custom directive transforms
    // in patchFlag analysis
    expect(node.arguments[3]).toMatch(PatchFlags.PROPS + '')
    expect(node.arguments[4]).toMatch(`"bar"`)
  })
github vuejs / vue-next / packages / compiler-core / __tests__ / codegen.spec.ts View on Github external
)
            ])
          ],
          // flag
          PatchFlags.FULL_PROPS + ''
        ])
      })
    )
    expect(code).toMatch(`
    return _${helperNameMap[CREATE_VNODE]}("div", {
      id: "foo",
      [prop]: bar,
      [foo + bar]: bar
    }, [
      _${helperNameMap[CREATE_VNODE]}("p", { "some-key": "foo" })
    ], ${PatchFlags.FULL_PROPS})`)
    expect(code).toMatchSnapshot()
  })
github vuejs / vue-next / packages / compiler-core / __tests__ / codegen.spec.ts View on Github external
createElementWithCodegen([
              `"p"`,
              createObjectExpression(
                [
                  createObjectProperty(
                    // should quote the key!
                    createSimpleExpression(`some-key`, true, locStub),
                    createSimpleExpression(`foo`, true, locStub)
                  )
                ],
                locStub
              )
            ])
          ],
          // flag
          PatchFlags.FULL_PROPS + ''
        ])
      })
    )
    expect(code).toMatch(`
    return _${helperNameMap[CREATE_VNODE]}("div", {
      id: "foo",
      [prop]: bar,
      [foo + bar]: bar
    }, [
      _${helperNameMap[CREATE_VNODE]}("p", { "some-key": "foo" })
    ], ${PatchFlags.FULL_PROPS})`)
    expect(code).toMatchSnapshot()
  })
github vuejs / vue-next / packages / compiler-core / __tests__ / transforms / transformElement.spec.ts View on Github external
}
      }
    )
    expect(root.helpers).toContain(RESOLVE_DIRECTIVE)
    expect(root.directives).toContain(`foo`)

    expect(node.callee).toBe(WITH_DIRECTIVES)
    expect(node.arguments).toMatchObject([
      {
        type: NodeTypes.JS_CALL_EXPRESSION,
        callee: CREATE_VNODE,
        arguments: [
          `"div"`,
          `null`,
          `null`,
          genFlagText(PatchFlags.NEED_PATCH) // should generate appropriate flag
        ]
      },
      {
        type: NodeTypes.JS_ARRAY_EXPRESSION,
        elements: [
          {
            type: NodeTypes.JS_ARRAY_EXPRESSION,
            elements: [
              `_directive_foo`,
              // exp
              {
                type: NodeTypes.SIMPLE_EXPRESSION,
                content: `hello`,
                isStatic: false
              },
              // arg
github vuejs / vue-next / packages / runtime-core / src / optional / keepAlive.ts View on Github external
function matches(pattern: MatchPattern, name: string): boolean {
  if (isArray(pattern)) {
    return (pattern as any).some((p: string | RegExp) => matches(p, name))
  } else if (isString(pattern)) {
    return pattern.split(',').indexOf(name) > -1
  } else if (pattern.test) {
    return pattern.test(name)
  }
  /* istanbul ignore next */
  return false
}
github vuejs / vue-next / packages / reactivity / src / reactive.ts View on Github external
function createReactiveObject(
  target: unknown,
  toProxy: WeakMap,
  toRaw: WeakMap,
  baseHandlers: ProxyHandler,
  collectionHandlers: ProxyHandler
) {
  if (!isObject(target)) {
    if (__DEV__) {
      console.warn(`value cannot be made reactive: ${String(target)}`)
    }
    return target
  }
  // target already has corresponding Proxy
  let observed = toProxy.get(target)
  if (observed !== void 0) {
    return observed
  }
  // target is already a Proxy
  if (toRaw.has(target)) {
    return target
  }
  // only a whitelist of value types can be observed.
  if (!canObserve(target)) {
github vuejs / vue-next / packages / runtime-core / src / optional / keepAlive.ts View on Github external
function matches(pattern: MatchPattern, name: string): boolean {
  if (isArray(pattern)) {
    return (pattern as any).some((p: string | RegExp) => matches(p, name))
  } else if (isString(pattern)) {
    return pattern.split(',').indexOf(name) > -1
  } else if (pattern.test) {
    return pattern.test(name)
  }
  /* istanbul ignore next */
  return false
}